Mega Code Archive

 
Categories / Java / Data Type
 

Check if String Contains another String

public class Main {   public static void main(String[] args) {     String haystack = "this is a test";     String needle1 = "Java";     int index1 = haystack.indexOf(needle1);     if (index1 != -1)       System.out.println("The string contains the substring " + needle1);     else       System.out.println("The string does not contain the substring " + needle1);   } } //The string does not contain the substring Java