Java String indexOf() Method
The indexOf() method has the following four forms:
public int indexOf(int ch):Returns the index of the first occurrence of the specified character in the string, or -1 if there is no such character in the string.
public int indexOf(int ch, int fromIndex):Returns the index of the first occurrence of the specified character in the string, starting the search from the fromIndex position, or -1 if there is no such character in the string.
int indexOf(String str):Returns the index of the first occurrence of the specified character in the string, or -1 if there is no such character in the string.
int indexOf(String str, int fromIndex):Returns the index of the first occurrence of the specified character in the string, starting the search from the fromIndex position, or -1 if there is no such character in the string.
Syntax
public int indexOf(int ch ) 或 public int indexOf(int ch, int fromIndex) 或 int indexOf(String str) 或 int indexOf(String str, int fromIndex)
Parameters
ch-- A character, Unicode code.
fromIndex-- The index position from which to start the search. The first character is 0, the second is 1, and so on.
str-- The substring to search for.

Return Value
Find the position where a string, or a character's Unicode code, appears in the string:
Example 1
The output result is:
-1 6 7 7 6 6
The index of the first occurrence of the specified substring in the string, starting from the specified index.
Example 2
The result of executing the above program is:
查找字符 o 第一次出现的位置 :12 从第14个位置查找字符 o 第一次出现的位置 :17 子字符串 SubStr1 第一次出现的位置:9 从第十五个位置开始搜索子字符串 SubStr1 第一次出现的位置 :-1 子字符串 SubStr2 第一次出现的位置 :16
Other Extensions
Java String Class