📜  如何在java代码示例中计算替换字符串

📅  最后修改于: 2022-03-11 14:52:34.338000             🧑  作者: Mango

代码示例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);
}