我想计算一个字符在字符串中出现的次数。我找到了一句台词:
int count = StringUtils.countMatches("a.b.c.d", ".");
但是,Android Studio 不支持 StringUtils
。我知道可以这样做:
int count = "a.b.c.d".length() - "a.b.c.d".replace(".", "").length();
但我想知道:Android 有内置的函数吗?
最佳答案
梯度:
dependencies {
...
implementation 'org.apache.commons:commons-lang3:3.0'
...
}
java:
import org.apache.commons.lang3.StringUtils;
从现在起您应该能够使用:
int count = StringUtils.countMatches("a.b.c.d", ".");
关于Java/Android : StringUtils. countMatches Android 替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33935241/