Possible Duplicate:
What is the cost / complexity of a String.indexof() function call
What is the complexity of java indexof(String str) method. I mean there are String matching algorithms like KMP which runs in linear time. I am implementing a system that needs to search for large substring in a really large string,so can I use java indexof(String str) method or I should to implement KMP.
The complexity of Java’s implementation of
indexOfisO(m*n)wherenandmare the length of the search string and pattern respectively.What you can do to improve complexity is to use e.g., the Boyer-More algorithm to intelligently skip comparing logical parts of the string which cannot match the pattern.