Answers for "count how many times a substring appears in a string java"

0

check how many times a character appears in a string java

str.chars().filter(num -> num == '$').count()
Posted by: Guest on January-31-2021
0

how to count an replace substring string in java

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);
Posted by: Guest on June-07-2020

Code answers related to "count how many times a substring appears in a string java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language