在Java中如何用String类中的indexof方法得到一个词的出现频率

public class Test{

public static void main(String[] args) {
String s="hello jack hello look me to see nohello";
String target="hello";//甚至可以为正则表达式
int count=0;
while(s.indexOf(target)>=0){
s=s.replaceFirst(target, "");
System.out.println(s);
count++;
}
System.out.println(target+" 出现的次数为:"+count);
}

}
原文地址:https://www.cnblogs.com/zhwl/p/3632125.html