A Unicode code point identifies an abstract character or character-related symbol. Java’s char stores a UTF-16 code unit, not necessarily one displayed character: code points above 0xFFFF use surrogate pairs outside the Basic Multilingual Plane. section 6.1
The fixed-width splitting mistake
Splitting a string with substring() by char positions can cut a surrogate pair or separate a combining character. An emoji such as code point 0x1F601 uses two chars; a waving-hand symbol with a skin-tone modifier can use four. The result may display replacement characters or lose the modifier. section 6.1
Avoid treating char positions as displayed-character positions:
- Use codePointAt() when character classification must handle supplementary code points. section 6.1
- Use codePoints() when processing or rebuilding text by code point. section 6.1
- Use BreakIterator for boundaries that should respect character-level text segmentation. section 6.1
String part = string.codePoints().skip(rowNumber * rowLength)
.limit(rowLength)
.collect(StringBuilder::new,
StringBuilder::appendCodePoint,
StringBuilder::append)
.toString();
Build fixed-size chunks by streaming code points and appending each complete code point rather than slicing UTF-16 units. section 6.1





