@SuppressWarnings("ConstantConditions")
    @Beta
    public static int countToken(@Nullable String target, String token) {
        checkArgument(token != null && !token.isEmpty(), "Expected non-empty token, got: '%s'", token);

        if (isNullOrEmpty(target)) {
            return 0;
        }

        int count = 0;
        int tokenIndex = 0;
        while ((tokenIndex = target.indexOf(token, tokenIndex)) != -1) {
            count++;
            tokenIndex += token.length();
        }
        return count;
    }
@ SuppressWarnings ( "ConstantConditions" ) @ Beta public static int countToken ( @ Nullable String target , String token ) { checkArgument ( token != null && ! token . isEmpty ( ) , "Expected non-empty token, got: '%s'" , token ) ; if ( isNullOrEmpty ( target ) ) { return 0 ; } int count = 0 ; int tokenIndex = 0 ; while ( ( tokenIndex = target . indexOf ( token , tokenIndex ) ) != - 1 ) { count ++ ; tokenIndex += token . length ( ) ; } return count ; }
Returns the number of times the token appears in the target.
@param token Token value to be counted.
@param target Target value to count tokens in.
@return the number of tokens.