RFR: 8364007: Add no-argument codePointCount method to CharSequence and String [v4]

Naoto Sato naoto at openjdk.org
Mon Jan 26 23:58:13 UTC 2026


On Mon, 26 Jan 2026 23:44:34 GMT, Tatsunori Uchino <duke at openjdk.org> wrote:

>> Adds `codePointCount()` overloads to `String`, `Character`, `(Abstract)StringBuilder`, and `StringBuffer` to make it possible to conveniently retrieve the length of a string as code points without extra boundary checks.
>> 
>> 
>> if (superTremendouslyLongExpressionYieldingAString().codePointCount() > limit) {
>>     throw new Exception("exceeding length");
>> }
>> 
>> 
>> Is a CSR required to this change?
>
> Tatsunori Uchino has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Improve JavaDoc
>   
>   Co-authored-by: Chen Liang <liach at openjdk.org>

src/java.base/share/classes/java/lang/Character.java line 10004:

> 10002:     /**
> 10003:      * {@return the number of Unicode code points in the {@code char} array}
> 10004:      * Unpaired surrogates count as one code point each.

It'd be better to replace "surrogates" with "surrogate code units." Applies to other method descriptions too.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r2729719433


More information about the core-libs-dev mailing list