From Core Java, vol. 1, 9th ed., p. 69:
The character ℤ requires two code units in the UTF-16 encoding. Calling
String sentence = "ℤ is the set of integers"; // for clarity; not in book char ch = sentence.charAt(1)
doesn't return a space but the second code unit of ℤ.
But it seems that sentence.charAt(1)
does return a space. For example, the if
statement in the following code evaluates to true
.
String sentence = "ℤ is the set of integers";
if (sentence.charAt(1) == ' ')
System.out.println("sentence.charAt(1) returns a space");
Why?
I'm using JDK SE 1.7.0_09 on Ubuntu 12.10, if it's relevant.