解决方法
我怀疑你只是对从char到int的转换感兴趣,这是隐含的:
for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); int value = c; System.out.println(value); }
编辑:如果你想处理代理对,你可以使用类似的东西:
for (int i = 0; i < text.length(); i++) { int codePoint = text.codePointAt(i); // Skip over the second char in a surrogate pair if (codePoint > 0xffff) { i++; } System.out.println(codePoint); }