Java String indexOf(String str, int fromIndex)
方法將返回指定字串在字串中從指定位置開始後第一次出現的索引,或如果未找到指定子字串,則返回-1
。
語法
以下是此方法的語法 -
int indexOf(String str, int fromIndex)
參數
str
- 要查找的子字串。fromIndex
- 開始的索引位置。
返回值
- 返回
str
所在的索引值。
示例
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str = new String("Welcome to xuhuhu.com");
String SubStr1 = new String("Yii");
System.out.print("Found Index :");
System.out.println(Str.indexOf(SubStr1, 15));
}
}
執行上面示例代碼,得到以下結果:
Found Index :-1
上一篇:
java中方法重載和方法重寫的區別
下一篇:無