Home >Java >javaTutorial >What are Surrogate Pairs in Java and How Do They Work?

What are Surrogate Pairs in Java and How Do They Work?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-29 10:42:10412browse

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.

  • Low surrogates occupy the range 0xD800 to 0xDBFF.
  • High surrogates occupy the range 0xDC00 to 0xDFFF.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn