1 public static void main(String[] args) { 2 int i = 0; 3 for (char c : ",。判断一个字符串是否有中文一般情况是利用Unicode编码".toCharArray()) { 4 i++; 5 System.out.println(i + ":" + isChinese(c)); 6 7 } 8 } 9 10 public static boolean isChinese(char c) { 11 Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); 12 if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS 13 || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS 14 || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A 15 || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B 16 || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION 17 || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS 18 || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION) { 19 return true; 20 } 21 return false; 22 }