RFR: 8302590: Add String.indexOf(int ch, int fromIndex, int toIndex)

Alan Bateman alanb at openjdk.org
Fri Feb 24 14:58:08 UTC 2023


On Thu, 16 Feb 2023 17:16:35 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

> Add an `indexOf()` variant allowing to specify both a lower and an upper bound on the search.

src/java.base/share/classes/java/lang/String.java line 2467:

> 2465:      *
> 2466:      * <p>As consequence of these rules, if {@code fromIndex} is greater than
> 2467:      * or equal to {@code toIndex}, then {@code -1} is returned.

Are there other examples in String where the equivalent of fromIndex > toIndex doesn't throw?

src/java.base/share/classes/java/lang/String.java line 2483:

> 2481:         return isLatin1() ? StringLatin1.indexOf(value, ch, fromIndex, toIndex)
> 2482:                 : StringUTF16.indexOf(value, ch, fromIndex, toIndex);
> 2483:     }

I assume you've add `@since 21` before integrating.

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

PR: https://git.openjdk.org/jdk/pull/12600


More information about the core-libs-dev mailing list