public class StringCount { public static void main(String[] args) { String ss = "kkabkkcdkkefkkskk"; String key = "kk"; System.out.println(getSubCount_2(ss,key)); } public static int getSubCount_2(String str,String key) { int count = 0 ; int index = 0 ; while ((index = str.indexOf(key)) != -1) { System.out.println(str); str = str.substring(index+key.length()); count++; } return count ; } }
时间: 2024-10-17 22:24:08