Java List 汉字进行排序

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

 

posted @ 2016-01-14 10:23  Bodi  阅读(1368)  评论(0编辑  收藏  举报