一、find(Str1,Str)
找出所有在Str1中出现的str的位置,如传入参数abcabc,ab返回位0,3
import java.util.ArrayList;
import java.util.List;
public class TestString {
public static void main(String[] args) {
List<Integer> list = new TestString().f("abcabcfafafcab", "ab");
for(Integer i:list){
System.out.println(i);
}
}
//abcabc ab
public List<Integer> f(String str1,String str2){
List<Integer> list = new ArrayList<Integer>();
int start_location = 0;
while(str1.indexOf(str2,start_location)!=-1){
int c = str1.indexOf(str2, start_location);
list.add(c);
start_location =c+str2.length();
}
return list;
}
}