Question on String#indexOf(String)

Joshua Bloch jjb at
Tue Apr 28 15:53:42 UTC 2009

I vaguely recall that madbot (Mike McCloskey) did some performance work on
this method, and came to the conclusion that more sophisticated algorithms
didn't actually pay for themselves in the common cases.  I'm copying him so
he can confirm or deny.

On Tue, Apr 28, 2009 at 3:50 AM, Jim Andreou <jim.andreou at> wrote:

> Hi,
> I wonder why String#indexOf(String) is implemented as it is. Apparently,
> when a character mismatch with the searched pattern is found, the pattern is
> only shifted by one character, but there are faster algorithms, for example
> see
> Was anything smarter tried out but had significant disadvantages for general
> use? What advantages does the current implementation have? It looks very
> pessimistic.
> Regards,
> Dimitris Andreou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the core-libs-dev mailing list