+ 3
How do i find a string inside a string??
For eg: I have: String str = "I love you" How do I check that the word love exists in the string ?
3 Answers
+ 8
Use contains() method
if (str.contains("love"){
System.out.print(true);
}
+ 3
You can use contains(), indexOf() and lastIndexOf() method to check if one String contains another String in Java or not.
for example:
System.out.print(str.contains ("love"));
System.out.print (str.indexOf ("love") != -1);
System.out.print (str.lastIndexOf ("love") != -1);