查找大字符串中小字符串出现大的次数

public class StringTest1
{
    public static void main(String[] args)
    {
        String s = "woaihefei,hefeibutongyubaima,wulunhefeihaishibaimahefei,zhaodaogongzuojiushihaoma";
        String s1 = "hefei";
        System.out.println(getCount(s,s1));
      
    }
    public static int getCount(String big,String small)
    {
        int count = 0;
        int index = 0;
        while ((index = big.indexOf(small)) != -1)
        {
            count++;
            big = big.substring(index+small.length());
        }
        return count;
    }
}


你可能感兴趣的:(JAVA)