用正则表达式[\u4e00-\u9fa5]
public static void main(String[] args) {
int count=0;String regEx = "[\\u4e00-\\u9fa5]";
//System.out.println(regEx);
String str = "中文fdas";
//System.out.println(str);
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
while (m.find()) {
for (int i = 0; i <= m.groupCount(); i++) {
count=count+1;
}
}
System.out.println("共有"+count+"个");
}