java判断是否是汉字
代码
public static boolean isChineseChar(char c) {
return String.valueOf(c).matches("[u4e00-u9fa5]");
}
测试用例
public class Test {
public static void main(String[] args) {
char a = ' ';
char b = 0;
char c = 'a';
char d = '中';
System.out.println(isChineseChar(a));
System.out.println(isChineseChar(b));
System.out.println(isChineseChar(c));
System.out.println(isChineseChar(d));
}
public static boolean isChineseChar(char c) {
return String.valueOf(c).matches("[u4e00-u9fa5]");
}
}
测试结果
false
false
false
true
编程界网,大量的免费Java入门教程,欢迎在线学习!