我想对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);
答案 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());
}
});
进行排序。