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);
        }
    }
}


 

相关文章:

  • 2021-10-01
  • 2021-07-01
  • 2021-12-17
  • 2022-03-14
  • 2022-03-09
  • 2022-12-23
  • 2021-06-20
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
相关资源
相似解决方案