How to check if a string contains the sequences of characters or not using java ?
How to check if a string contains the sequences of characters or not using java ?
Contain() Method
- java.lang.String.contains() method searches the sequence of characters in the given string. If sequence of char values are found in this string then print Yes otherwise print No.
Sample Code in Java
// Java program to demonstrate working
// contains() method
public class Wikitechy {
// Driver code
public static void main(String args[]) {
String s1 = "Welcome to Wikitechy";
if (s1.contains("kite") == true) {
System.out.println("Yes");
}
// prints true
else {
System.out.println("No");
}
}
}
Output
Yes