Check out example codes for "how to count an replace string in java". It will help you in understanding the concepts better.

Code Example 1

public static void main(String[] args) throws Exception {
        String word = "abcdefg";
        System.out.println(word.length());
        System.out.println(word.replace("a", "").length());
        int a_counter = word.length() - word.replace("a", "").length();
        System.out.println(a_counter);
}

Learn ReactJs, React Native from akashmittal.com