2E80-A4CF:
包含了中日朝部首补充、康熙部首、表意文字描述符、中日朝符号和标点、日文平假名、日文片假名、注音字母、谚文兼容字母、象形字注释标志、注音字母扩展、中日朝笔画、日文片假名语音扩展、带圈中日朝字母和月份、中日朝兼容、中日朝统一表意文字扩展A、易经六十四卦符号、中日韩统一表意文字、彝文音节、彝文字根
F900-FAFF:
中日朝兼容表意文字
FE30-FE4F:
中日朝兼容形式
所以,一般用4E00-9FA5已经可以,如果要更广,则用2E80-A4CF || F900-FAFF || FE30-FE4F
package javaTest; import java.util.Random; public class Test { private static int chineseStart = Integer.parseInt(String.valueOf(0x4e00)); private static int chineseEnd = Integer.parseInt(String.valueOf(0x9FA5)); /** * unicode * 汉字区间:4E00-9FA5 * 注音符号:3100-312F * 注音符号(闽南语、客家语扩展):31A0-31BF */ private static String randomChinese(){ Random random = new Random(); int position = random.nextInt(chineseEnd-chineseStart)+chineseStart; System.out.println(position+"--"+chineseEnd); String code = Integer.toHexString(position); return decode("\\u"+code); } /** * @return 所有的中文 */ public String getAllChinese(){ StringBuilder sb = new StringBuilder(); for(int i=chineseStart;i<=chineseEnd;i++){ String ss = Integer.toHexString(i); sb.append(decode("\\u"+ss)); } return sb.toString() ; } /** * 判断是否为中文 * @return */ public static boolean isChinese(String string){ boolean flag = false; for (int i = 0; i < string.length(); i++) { char c = string.charAt(i); if ((c >= 0x4e00) && (c <= 0x9FA5)) { flag = true; } } return flag; } public static void main(String[] args) throws InterruptedException { System.out.println(randomChinese()); System.out.println(isChinese("哈")); } /** * 将unicode编码转成中文字符 * @param unicodeStr * @return */ public static String decode(String unicodeStr) { if (unicodeStr == null) { return null; } StringBuffer sb = new StringBuffer(); int maxLoop = unicodeStr.length(); for (int i = 0; i < maxLoop; i++) { if (unicodeStr.charAt(i) == '\\') { if ((i < maxLoop - 5) && ((unicodeStr.charAt(i + 1) == 'u') || ( unicodeStr.charAt(i + 1) == 'U'))) try { sb.append((char) Integer.parseInt(unicodeStr.substring(i + 2, i + 6), 16)); i += 5; } catch (NumberFormatException localNumberFormatException) { sb.append(unicodeStr.charAt(i)); } else sb.append(unicodeStr.charAt(i)); } else { sb.append(unicodeStr.charAt(i)); } } return sb.toString(); } }