如果我输入字符串“in the win”。我将如何让程序在该字符串中找到“in”对。那里有两个。我知道要在字符串中找到一个字符的出现,但是一对怎么样。
谢谢。
最佳答案
使用 Apache Commons StringUtils
类 (http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html) 的 countMatches
方法。
StringUtils.countMatches("in the win", "in");
关于java - 如何计算字符串中的对数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22623566/