how to count an replace substring string in java

Solutions on MaxInterview for how to count an replace substring string in java by the best coders in the world

showing results for - "how to count an replace substring string in java"
Alessandro
11 Jul 2019
1String str = "helloslkhellodjladfjhello";
2String findStr = "hello";
3int lastIndex = 0;
4int count = 0;
5while(lastIndex != -1){
6    lastIndex = str.indexOf(findStr,lastIndex);
7    if(lastIndex != -1){
8        count ++;
9        lastIndex += findStr.length();
10    }
11}
12System.out.println(count);
queries leading to this page
java replace stringwhat does replace method do in javareplace function in javas replace javacount no of substrings java with matched stringreplace in a string javajava count occurrences substring in stringreplace in javareplace string java withcount of substring in string javajava builtin replacecount how many times a substring appears in a string javareplace method in javahow to use replace functionin javareplacing a specific value in a string javacount occurrences of a substring in a string javacount substring in a string javahow to use replace function in javareplace in string in javareplace method javajava string count occurrences of substringreplace 28 29 javareplace 28 29 method in java replace 28 29 javareplace in java stringjava 7b 7d replacejava string contains count occurancesstring replace javajava str replace stringreplace string in javafind string and replace in javacount occurrences of string in string javahow to count an replace substring string in javacount substring in string javajava string count substringreplace in java which packagereplace string javareplacing data in strng in java replace javareplace a string javajava replacestring replace javaused replace with a veraible javajava count substrings in stringjava replace methodcount instances of substring in string javahow to count substring in a string in javastring replace in javajava count occurrences of substring in stringhow replace works in javahow to count an replace substring string in java