java字符判断是否是中文

   String a = "你好sjscv";
        for(int i = 0; i < a.length(); i++){
            char b =a.charAt(i);
            if(String.valueOf(b).matches("[\u4E00-\u9FA5]+")){
                System.out.println(b);
            }
        }

另一种

    public static  boolean isChinese(char c) {
        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
        if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
                || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
            return true;
        }
        return false;
    }

你可能感兴趣的:(java字符判断是否是中文)