汉字比较实现
java.text.Collator类中有一个getInstance(Locale desiredLocale) 方法可以解决对汉字排序的问题
public class MyCompare implements Comparator<Student> { @Override public int compare(Student o1, Student o2) { String strclass1 = o1.getClassid(); String strclass2 = o2.getClassid(); String strname1 = o1.getName(); String strname2 = o2.getName(); if ((strclass1.compareTo(strclass2)) != 0) { return strclass1.compareTo(strclass2); } else { Collator instance = Collator.getInstance(Locale.CHINA); return instance.compare(strname1, strname2); } } }