java 匹配字符串中的中文个数

/**
* 匹配字符串中有多少个中文
* wangxq 2015年7月1日 16:18:52
* @param recordStr
* @return
*/

    public Integer parseRecordStr(String recordStr){
        Integer countNum = 0;
        if(recordStr){
            // 要匹配的字符串
            String reg_charset ="[\u4E00-\u9FA5]";
            Pattern p = Pattern.compile(reg_charset);

            Matcher m = p.matcher(recordStr);
            while (m.find()) {
                countNum = countNum + 1
            }
        }
        return countNum;
    }
原文地址:https://www.cnblogs.com/jayGold/p/4623789.html