获取一个字符串中,另一个字符串出现的次数



public class DemoText {

    public static void main(String[] args) {
        
        fun1();
    }
    public static void fun1(){
            String s = "hello word Ok Yes hello hello";
            
            int sum=0;
            while(s.contains("lo")){
                
                sum++;
                s=s.replaceFirst("lo", "");
            }
            System.out.println("指定字符串在原字符中出現:"+sum+"次");
        }
}

posted @ 2019-03-18 22:18  白云之间  阅读(1505)  评论(0编辑  收藏  举报