codePointAt takes a char index.
The index refers to char values โโ(Unicode code units) and ranges from 0 to length() - 1 .
This line contains six code points. The offsetByCodePoints call returns the index after 6 code points, which is char -index 7. Then you try to get codePointAt(7) , which is at the end of the line.
To understand why, think that
"".offsetByCodePoints(0, 0) == 0
because to count all 0 code points you need to count past 0 char s.
By extrapolating this to your line, in order to count the past of all 6 codes, you need to count the past of all 7 char s.
Perhaps viewing codePointAt in use will make this clear. This is an idiomatic way to iterate over all code points in a string (or CharSequence ):
for (var charIndex = 0, nChars = s.length(), codepoint; charIndex < nChars; charIndex += Character.charCount(codepoint)) { codepoint = s.codePointAt(charIndex);
source share