Suppose i have 2 strings:
String1 = "I love dogs and cats"
String2 = "love dogs"
and i want to find if string1 contains string2. How do i do it ??
Thanks and regards
Suppose i have 2 strings:
String1 = "I love dogs and cats"
String2 = "love dogs"
and i want to find if string1 contains string2. How do i do it ??
Thanks and regards
The String java API has a method that does what you want. This method is contains()
. Here is how to use it :
String str1 = "I love dogs and cats";
String str2 = "love dogs";
boolean isIn = str1.contains(str2); // isIn = true.
boolean isIn = str1.contains("love cats"); // isIn = false