#Java string to codepoints code
Although java String has support for functions like codePointAt, codePointBefore and codePointCount, these functions are still based on representing a single code point as two characters for surrogate pairs, thus the index passed to these functions are based on this definition. That is a UTF-16 code point with a high and low surrogate pair would be counted as two characters in java. The String implementation in java represents the supplementary characters as surrogate pairs. 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). The Java platform uses the UTF-16 representation in char arrays and in the String and StringBuffer classes. Characters whose code points are greater than U+FFFF are called supplementary characters. The set of characters from U+0000 to U+FFFF is sometimes referred to as the Basic Multilingual Plane (BMP). (Refer to the definition of the U+ n notation in the Unicode Standard.) The range of legal code points is now U+0000 to U+10FFFF, known as Unicode scalar value.
The Unicode Standard has since been changed to allow for characters whose representation requires more than 16 bits.
The char data type (and therefore the value that a Character object encapsulates) are based on the original Unicode specification, which defined characters as fixed-width 16-bit entities. Let us first understand what code points and surrogate pairs refer to: