Home >Java >javaTutorial >What are Surrogate Pairs in Java and How Do They Work?
Understanding Surrogate Pairs in Java
When examining the StringBuffer documentation, particularly the reverse() method, you may encounter the term "surrogate pairs." This concept plays a crucial role in representing characters beyond the range of typical UTF-16 code units.
What is a Surrogate Pair?
A surrogate pair is a technique used in Unicode encoding to represent characters with code-points greater than 0xFFFF. In the UTF-16 scheme, such characters are encoded using a pair of 16-bit code units.
Low and High Surrogates
Surrogate code units fall into two categories: low surrogates and high surrogates.
A character with a code-point exceeding 0xFFFF is represented by a high surrogate followed by a low surrogate. The high surrogate represents the most significant bits (MSB) of the character's code-point, while the low surrogate represents the least significant bits (LSB).
The above is the detailed content of What are Surrogate Pairs in Java and How Do They Work?. For more information, please follow other related articles on the PHP Chinese website!