我發現了一個棘手的地方,找不到任何答案,爲什麼發生這種情況。編碼 - codePointCount和長度之間的不同結果
主要問題是字符串有多長。
是否包含一個或兩個字符。
代碼:
public class App {
public static void main(String[] args) throws Exception {
char ch0 = 55378;
char ch1 = 56816;
String str = new String(new char[]{ch0, ch1});
System.out.println(str);
System.out.println(str.length());
System.out.println(str.codePointCount(0, 2));
System.out.println(str.charAt(0));
System.out.println(str.charAt(1));
}
}
輸出:
?
2
1
?
?
有什麼建議?
我建議你花些時間閱讀[本文](http://kunststube.net/encoding/) –
你期望輸出什麼? –