countMatches
public static int countMatches(String str,
String sub)
Counts how many times the substring appears in the larger String.
A null or empty ("") String input returns 0.
StringUtils.countMatches(null, *) = 0
StringUtils.countMatches("", *) = 0
StringUtils.countMatches("abba", null) = 0
StringUtils.countMatches("abba", "") = 0
StringUtils.countMatches("abba", "a") = 2
StringUtils.countMatches("abba", "ab") = 1
StringUtils.countMatches("abba", "xxx") = 0
Parameters:
str - the String to check, may be null
sub - the substring to count, may be null
Returns:
the number of occurrences, 0 if either String is null
Partager