在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);
}

}
posted @ 2014-03-29 09:06  郑文亮  阅读(493)  评论(0编辑  收藏  举报