【发布时间】:2015-10-13 08:32:46
【问题描述】:
String word = "abcdefg";
int a_counter = word.length() - word.replace("a", "").length();
此代码为我提供了“单词”字符串中“a”的计数。但是有人可以解释一下它是如何工作的吗?(Java)
【问题讨论】:
-
它给出 1 作为输出,这是正确的。那有什么问题?
-
@Rehman:“但是有人可以解释一下它是如何工作的吗?”
标签: java string replace count char