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

Viktor Klang duke at openjdk.org
Fri Feb 24 16:30:08 UTC 2023


On Fri, 24 Feb 2023 15:32:34 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

>> I simply extrapolated the behavior from `indexOf(int ch,int fromIndex), which has a similar note:
>> 
>>      * There is no restriction on the value of {@code fromIndex}. If it
>>      * is negative, it has the same effect as if it were zero: this entire
>>      * string may be searched. If it is greater than the length of this
>>      * string, it has the same effect as if it were equal to the length of
>>      * this string: {@code -1} is returned.
>
> This is the behavior of the underlying implementation as well.

Personally I would expect `string.substring(fromIndex, toIndex).indexOf(ch)` to behave isomorphically to `string.indexOf(ch, fromIndex, toIndex)`

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

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


More information about the core-libs-dev mailing list