Java精确判断一个字符串是否有中文

如题所述

public boolean isChinese(String aa){

char [] cha = aa.toCharArray();

for(int i =0;i<cha.length;i++){
if(cha[i] >= 0x4e00 && cha[i] <= 0x9fbb){
return true;
}
}
return false;
}
@Test
public void testChinese(){
String aa = "中文abc";
String bb = "ABC";
boolean a = isChinese(aa);
boolean b = isChinese(bb);
if(a){
System.out.println("含有中文");
}else{
System.out.println("没有中文");
}
}
温馨提示:答案为网友推荐,仅供参考
相似回答