public static int getSubCount_2(String str, String key) {
int count = 0;
int index = 0;
while ((index = str.indexOf(key, index)) != -1) {
index = index + key.length();
count++;
}
return count;
}
public static void main(String[] args) {
String str = "kkabkkcdkkefkks";
//控制台输出4
System.out.println(getSubCount_2(str, "kk"));
}
java判断一个字符串包含多少其他字符串
最新推荐文章于 2024-07-29 14:33:48 发布