title: Choice of algorithm for .indexOf method in Java
body: <p>I was just looking at the implementation of the Java <code>String</code> class's <code>.indexOf()</code> method and it seems the author of the code uses the brute force algorithm to find the substring in a given string.  That is, the approach runs in O(mn), where m and n are the length of the source and target strings, respectively.</p>
  
  <p>Why didn't the author use a more efficient algorithm like Rabin-Karp, which has a runtime complexity of O(m + n) if a good hash function is provided ? </p>
  
  <p>I might be missing out on the complete knowledge behind the reason for this implementation and hence wanted to understand.</p>