如果我有一个 List< Integer >
其整数值为 Unicode code point数字。如何构建 String
由这些代码点确定的字符对象?
例如:
List < Integer > codePoints = List.of( 100, 111, 103, 128054 ) ;
...或:
List < Integer > codePoints = "cat".codePoints().boxed().toList();
如何获得另一个String
具有值 cat
的对象来自codePoints
?
最佳答案
字符串
has a constructor它采用一个 int
代码点数字数组。
int[] ints = codePoints.stream().mapToInt(i -> i).toArray();
String string = new String(ints, 0, ints.length);
转换List
-> Stream
-> IntStream
-> int[]
-> String
关于java - 从代码点整数列表生成 String 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68606229/