
Don't form strings containing partial characters from variable-width encodings), UTF-16 is a variable-width encoding.
#JAVA STRING TO CODEPOINTS CODE#
The lower (least significant) 21 bits of int are used to represent Unicode code points, and the upper (most significant) 11 bits must be zero. An int value represents all Unicode code points, including supplementary code points. In this representation, supplementary characters are represented as a pair of char values, the first from the high-surrogates range, (\uD800-\uDBFF), the second from the low-surrogates range (\uDC00-\uDFFF).Ī char value, therefore, represents BMP code points, including the surrogate code points, or code units of the UTF-16 encoding. The Java platform uses the UTF-16 representation in char arrays and in the String and StringBuffer classes. According to the Java API class Character documentation (Unicode Character Representations): To support supplementary characters without changing the char primitive data type and causing incompatibility with previous Java programs, supplementary characters are defined by a pair of Unicode code units called surrogates. Such characters are generally rare, but some are used, for example, as part of Chinese and Japanese personal names. The set of characters from U+0000 to U+FFFF is called the basic multilingual plane (BMP), and characters whose code points are greater than U+FFFF are called supplementary characters. The range of Unicode code points is now U+0000 to U+10FFFF.

The Unicode Standard has since been changed to allow for characters whose representation requires more than 16 bits. The char data type is based on the original Unicode specification, which defined characters as fixed-width 16-bit entities.
