Answers for "number of occurences of a substring in a string java substring method"

2

number of occurence string in java

public class StringNumberOfOccurenceLetter {

    private static int countOccurences(String word, char character){

        int count = 0;
        for (int i = 0; i < word.length() ; i++) {
            if (word.charAt(i)==character){
                count++;
            }
        }
        return count;

    }
         public static void main(String[] args) {


        int count = countOccurences("dddssad", 'a');
    }


}
Posted by: Guest on January-14-2021
0

find number of occurrences of a substring in a string java

public static int count(String str, String target) {
    return (str.length() - str.replace(target, "").length()) / target.length();
}
Posted by: Guest on October-29-2020

Code answers related to "number of occurences of a substring in a string java substring method"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language