public static int countMatches(CharSequence str, CharSequence sub) {
        if (isEmpty(str) || isEmpty(sub)) {
            return 0;
        }
        int count = 0;
        int idx = 0;
        while ((idx = CharSequenceUtils.indexOf(str, sub, idx)) != INDEX_NOT_FOUND) {
            count++;
            idx += sub.length();
        }
        return count;
    }
<p>Counts how many times the substring appears in the larger string.</p>

<p>A {@code null} or empty ("") String input returns {@code 0}.</p>

<pre>
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
</pre>

@param str  the CharSequence to check, may be null
@param sub  the substring to count, may be null
@return the number of occurrences, 0 if either CharSequence is {@code null}
@since 3.0 Changed signature from countMatches(String, String) to countMatches(CharSequence, CharSequence)
android/android_framework/base/src/main/java/lang3/StringUtils.java