public class StringTest {
public static void main(String args[]) {
String s = "hello, this is a test this is a test this is a this is test";
String p = "test";
for(int i = 0; i < s.length(); i ++) {
int at = s.indexOf(p, i);
if(at < 0) {
break;
}
System.out.println(p + "@" + at);
i = at;
}
}
}
获取一个字符串在另个字符串中出现的所有位置
最新推荐文章于 2021-10-31 08:57:10 发布
本文提供了一个使用Java进行字符串查找的简单示例。通过遍历和indexOf方法定位特定子串的位置,展示了基本的字符串操作技巧。
5万+

被折叠的 条评论
为什么被折叠?



