UNICODE ENCODING

What is UTF-16?

UTF-16 represents Unicode code points with one or two 16-bit code units. This model is important when working with Java text.

How does UTF-16 work?

Common characters fit in one 16-bit code unit. Code points beyond the Basic Multilingual Plane, including many emoji, use two code units: a surrogate pair .

The connection to Java

Java char stores one 16-bit code unit, while String.length() counts code units rather than always counting visible characters. One emoji can therefore have a length of 2.

Do not confuse

One char does not always mean one complete Unicode character. Java provides these methods for safe code-point processing: codePointAt() and codePoints().

In brief

UTF-16 does not change the Unicode character's value. It only specifies how its code point becomes bytes for storage or transmission.

← Back to the Unicode overview