使用Locale排序列表

时间:2014-10-02 18:08:32

标签: android sorting

我想对ArrayList<Object>进行排序。 (字母排序)

我使用以下代码进行排序:

    Collections.sort(arr_items, new Comparator<Helper>() {


        @Override
        public int compare(Helper one, Helper two) {
            // TODO Auto-generated method stub

            return one.getTitle().compareTo(two.getTitle());
        }

    });

现在,如果我想设置一个Locale,我该怎么办?

    Locale arrabic= new Locale("ar");
    Collator arrabicCollator = Collator.getInstance(arrabic);

1 个答案:

答案 0 :(得分:1)

您的Comparator需要像Collator这样使用:

Locale arrabic= new Locale("ar");
final Collator arrabicCollator = Collator.getInstance(arrabic);
Collections.sort(arr_items, new Comparator<Helper>() {

    @Override
    public int compare(Helper one, Helper two) {
        return arrabicCollator.compare(one.getTitle(), two.getTitle());
    }

});

进行排序。