From the Java Language Specification, Section 3.10.5 String Literals:
Characters may be represented by escape sequences - one escape sequence for characters in the range U+0000 to U+FFFF, two escape sequences for the UTF-16 surrogate code units of c开发者_开发百科haracters in the range U+010000 to U+10FFFF.
What does this mean? If a character falls within the range U+0000 to U+FFFF, then one escape sequence may be used. How different is one escape sequence from two escape sequences?
By escape sequence, does it refer to \n
, \r
and similar? Are these one sequence or two escape sequences?
From u+0000 to u+ffff, each number (if you will) represents a characters. However, some unicode characters (called surrogate pairs) are combination of two numbers in the u+010000 to u+10ffff. So if you have a number u+010000 to u+10ffff, then a second one is required to represent a valid character.
By escape sequence, they mean stuff like \u0000
(which you can use in a String
literal to represent a unicode character).
精彩评论