1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/* Java String Contains example. This Java String contains examples shows how to use contains method of Java String class. */ public class JavaStringContains { public static void main(String args[]){ String str1 = "Hello World"; String str2 = "Hello"; /* * To check whether the string contains specified character sequence use, * boolean contains(CharSequence sq) * method of Java String class. * * This method returns true if the string contains given character sequence. * Please note that contains method is added in Java 1.5 */ boolean blnFound = str1.contains(str2); System.out.println("String contains another string? : " + blnFound); /* * Please also note that the comparison is case sensitive. */ } } /* Output of Java String contains example would be String contains another string? : true */ |
Add Comment