public class Test {
public static void main(String[] args) {
//找到了返回位置的开始的下标
String str = "hello word";
//从头开始查找子字符串位置
System.out.println(str.indexOf("ell"));
//从指定位置查找子字符串位置
System.out.println(str.indexOf("or", 2));
//没找到返回 -1
System.out.println(str.indexOf("oll"));
}
}
实现方法 indexOf, 能够找出字符串子串存在的位置
最新推荐文章于 2022-03-20 15:52:22 发布