Determining whether a String contains another String

Use java.lang.String.indexOf(String) to check if one string contains another. indexOf() will return -1 if the string is not found and the starting index of the string if it is found.

   String a = "Some text";
   String b = "text";
 
   if (a.indexOf(b) != -1) {
      System.out.println("String a contains String b, starting at position " + a.indexOf(b));
   } else {
      System.out.println("String a does not contain String b");
   }