Javaは、中国のためにアルファベット順にソート

実装コンパレータインタフェースは、Collat​​or.getInstanceによって特定のロケールを指定することができることがJDK自身のクラスで照合()で

    private void sortAttribute(List<Student> list){
        Comparator<Object> comparator = new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                Student attribute1 = (Student) o1;
                Student attribute2 = (Student) o2;
                Collator collator = Collator.getInstance(java.util.Locale.CHINA);
                return collator.getCollationKey(attribute1.getName()).compareTo(collator.getCollationKey(attribute2.getName()));
            }
        };
        Collections.sort(list,comparator);
    }
公開された46元の記事 ウォン称賛13 ビュー60000 +

おすすめ

転載: blog.csdn.net/luliuliu1234/article/details/80589466