java-统计大字符串中小字符串的个数

package com.day7.one;

  public class Test4 {

  /**
  * 需求:统计大串中小串出现的次数
  */
    public static void main(String[] args) {
      String max="woaikobe,kobebutongxuqitaqiuxing,zhejiushiwoaikobedeyuanyin";
      String min="kobe";
      int count=0;
      int index=0;
      while((index=max.indexOf(min))!=-1)
      {
        count++;
        max=max.substring(index+min.length());
      }
      System.out.println(count);
    }

}

posted @ 2017-12-26 22:15  简简单单zjl  阅读(477)  评论(0编辑  收藏  举报