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中方法重载和方法重写的区别
下一篇:无