来自Core Java,第一卷.第1版,第9版,p.69:
字符ℤ需要两个UTF-16编码的代码单元.调用
Run Code Online (Sandbox Code Playgroud)String sentence = "? is the set of integers"; // for clarity; not in book char ch = sentence.charAt(1)不返回空格而是返回second的第二个代码单元.
但它似乎sentence.charAt(1) 确实返回了一个空间.例如,if以下代码中的语句求值为true.
String sentence = "? is the set of integers";
if (sentence.charAt(1) == ' ')
System.out.println("sentence.charAt(1) returns a space");
Run Code Online (Sandbox Code Playgroud)
为什么?
我在Ubuntu 12.10上使用JDK SE 1.7.0_09,如果它是相关的.