First, contains method
1: Description
The Java.lang.String.contains () method returns True if and only if this string contains a specified sequence of char values
2: Statement
Public Boolean contains (Charsequence s)
3: Return value
This method returns true, or False if this string is contained.
4: Example
public static void Main (string[] args) {
String str = "abc";
Boolean status = Str.contains ("a");
if (status) {
System.out.println ("included");
} else{
System.out.println ("not included");
}
Second, indexof method
1: Description
The purpose of java.lang.String.indexOf () is to find the position of a word in a string, as well as to determine whether a character is contained in a string.
2: Statement
int indexOf (int ch,int fromindex)
3: Return value
The return value of indexof is int
4: Example
public static void Main (string[] args) {
String str1 = "ABCDEFG";
int result1 = Str1.indexof ("a");
if (result1!=-1) {
System.out.println ("string str contains substring" a "" +result1);
} else{
System.out.println ("String str does not contain substring" a "" +result1);
}