package Test;
import java.util.ArrayList;
import java.util.List;
public class Test5 {
public static void main(String[] args) {
String str = "hello,world!hello,china!hello,jiangsu!";
String s="hello";
List<Integer> list = getIndexOfStr(str, s);
for (Integer i : list) {
System.out.println(i);
}
}
public static List<Integer> getIndexOfStr (String str,String s) {
List<Integer> rs=new ArrayList<Integer>();
if(null!=str) {
Integer index=0;
while(index<str.length()){
index=str.indexOf(s,index);
if (index < 0) {
//不存在,就结束循环
break;
}
else {
rs.add(index);
index=index+s.length();
}
}
}
//返回rs
return rs;
}
}