Comparator<Person> cmp = new Comparator<Person>() {  
  
    public int compare(Person o1, Person o2) {  
        Comparator<Object> cmp = Collator.getInstance(java.util.Locale.CHINA);  
  
        String[] strs1 = new String[2];  
        strs1[0] = o1.getName1();  
        strs1[1] = o2.getName1();  
  
        String[] strs2 = new String[2];  
        strs2[0] = o1.getName2();  
        strs2[1] = o2.getName2();  
  
        Arrays.sort(strs1, cmp);  
        Arrays.sort(strs2, cmp);  
  
        if (strs1[0].equals(strs1[1])) {  
            if (strs2[0].equals(strs2[1])) {  
                return 0;  
            }  
  
            if (strs2[0].equals(o1.getName2())) {  
                return -1;  
            } else {  
                return 1;  
            }  
        } else {  
            if (strs1[0].equals(o1.getName1())) {  
                return -1;  
            } else if (strs1[0].equals(o2.getName1())) {  
                return 1;  
            }  
        }  
  
        // 在这里实现你的比较  
  
        return 0;  
    }  
};  
// 调用 Collections.sort(sabin, cmp);

 

相关文章:

  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-23
  • 2021-08-04
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
  • 2021-09-28
相关资源
相似解决方案