how to count an replace string in java

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

showing results for - "how to count an replace string in java"
Riccardo
05 Oct 2019
1public static void main(String[] args) throws Exception {
2        String word = "abcdefg";
3        System.out.println(word.length());
4        System.out.println(word.replace("a", "").length());
5        int a_counter = word.length() - word.replace("a", "").length();
6        System.out.println(a_counter);
7}