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);
}
}
在Java中如何用String类中的indexof方法得到一个词的出现频率
最新推荐文章于 2023-02-11 14:04:43 发布
本文介绍了几个实用的Java程序示例,展示了如何使用indexOf等方法来处理字符串,包括计数特定子串出现次数的方法。
3591

被折叠的 条评论
为什么被折叠?



