725です。
> lengthはコードポイント単位
はコードユニット単位でした、すみません。

>>726
ありがとうございます。
文字列全体の長さが欲しいときは
str.codePointCount(0, str.length())
とするんですかね。