public class IsHaveHanZi { public static boolean isHaveHanZi(String str){ boolean flag=true; int count = 0; String regEx = '[\\u4e00-\\u9fa5]'; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(str); while (m.find()) { for (int i = 0; i <= m.groupCount(); i++) { count = count + 1; } } if(count==0){ flag=false; } return flag; } public static void main(String[] args) { System.out.println(isHaveHanZi('我是sssss')); } } |
|