Inefficient code of String.indexOf(String)

Martin Buchholz martinrb at
Mon Jun 17 06:14:55 UTC 2013

You are not the first person to have this idea.
It is unlikely that you will succeed in changing the algorithm, because the
jit-optimized brute-force algorithm is "almost always" faster.
But go ahead and prove me wrong!

On Sun, Jun 16, 2013 at 3:53 AM, Anubhav Chaturvedi <
mailforanubhav at> wrote:

> Hello,
> I have recently started to explore the source code and am new to the open
> source community. I observed that in String.class within java.lang , the
> indexOf method, line 1715, uses the bruteforce approach when it comes to
> string matching. This method is used by the contains(CharSequence) method.
> There are a number of algorithms that can perform the task more
> efficiently.
> I would like to bring the required changes and needed your advice on this.
> --
> *Regards,*
> *Anubhav Chaturvedi*
> *Birla Institute of Technology & Science, Pilani*
> KK Birla Goa Campus
> +91-9637399150

More information about the core-libs-dev mailing list