📜  如何在java代码示例中计算替换子字符串字符串

📅  最后修改于: 2022-03-11 14:52:16.832000             🧑  作者: Mango

代码示例1
String str = "helloslkhellodjladfjhello";
String findStr = "hello";
int lastIndex = 0;
int count = 0;
while(lastIndex != -1){
    lastIndex = str.indexOf(findStr,lastIndex);
    if(lastIndex != -1){
        count ++;
        lastIndex += findStr.length();
    }
}
System.out.println(count);