Java String contains() Method
The contains() method is used to determine whether a string contains the specified character or substring.
Syntax
public boolean contains(CharSequence chars)
Parameters
chars-- The character or substring to check for.
Return Value
Returns true if the specified character or substring is contained, otherwise returns false.
Example
The following example checks whether Example contains a character or character sequence:
Example
public class Main {
public static void main(String[] args) {
String myStr = "Example";
System.out.println(myStr.contains("Run"));
System.out.println(myStr.contains("o"));
System.out.println(myStr.contains("s"));
}
}
The output of the above program is:
true true false
Other Extensions
Java String Class