Contains method in Java String
Contains method in Java String
The contains() method searches for a string of characters in this string. It returns true if a sequence of char values is found in this string, otherwise returns false.
Syntax:
public boolean contains(CharSequence sequence)
Example:
public class ContainsExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
String name = "what do you know about me";
System.out.println(name.contains("do you know"));
System.out.println(name.contains("about"));
System.out.println(name.contains("hello"));
}
}
Result:

Did you find this article helpful?
Support the author so they can write more quality articles!