一个字符串在另一个字符串中出现的次数
public class FindString {
public static void main(String[] args) {
String s = "javaeejavajajavavajavavajajjaa";
//方法一
String d = "java";
Pattern p = Pattern.compile(d);
Matcher m = p.matcher(s);
int count = 0;
while(m.find()){
count++;//String aa = s.substring(m.start(), m.end());//System.out.println(aa);
}
System.out.println(count);
//方法二
count = 0;
int index = -1;
while((index = s.indexOf(d,index))!=-1){
count++;
index = d.length()+index;
}
System.out.println(count);
}
}