-3

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

Jens
  • 67,715
  • 15
  • 98
  • 113
  • 1
    I'm voting to close this question as off-topic because Looks like homework that sould be done by OP itself – Jens May 17 '17 at 11:28
  • 1
    Look at `String`'s methods. Your question has the correct keyword. – Stefan Warminski May 17 '17 at 11:30
  • 2
    Possible duplicate of [How to search a string in another string?](http://stackoverflow.com/questions/9276040/how-to-search-a-string-in-another-string) – Tom May 17 '17 at 11:32

1 Answers1

0

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
TheWildHealer
  • 1,546
  • 1
  • 15
  • 26