Java:String. How does the contains (string) function work in Java?
•
Java
I know that the time complexity of brute force method is n * m (M is the length of the first string and N is the length of the other string), which is used to test whether the string contains another string. However, I wonder whether the existence is a better solution?
boolean contains(String input,String search)
Solution
You can take a look at source:
public boolean contains(CharSequence s) { return indexOf(s.toString()) > -1; }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码