美文网首页
判断String字符串中包含某个指定/特殊字符的个数

判断String字符串中包含某个指定/特殊字符的个数

作者: 点映文艺 | 来源:发表于2021-07-15 14:56 被阅读0次
    /**
     * 判断str中包含key的个数
     * @param str1
     * @param str2
     * @return counter
     */
    static int counter = 0;
    public static int countKey(String str, String key) {
        if (str.indexOf(key) == -1) {
            return 0;
        } else if (str.indexOf(key) != -1) {
            counter++;
            countKey(str.substring(str.indexOf(key) +
                    key.length()), key);
            return counter;
        }
        return 0;
    }

相关文章

网友评论

      本文标题:判断String字符串中包含某个指定/特殊字符的个数

      本文链接:https://www.haomeiwen.com/subject/wgappltx.html