Reputation: 17393
I would like to sort an ArrayList<Object>
. ( alphabet sort)
I am using below codes to sorting :
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());
}
});
now if I want to set a Locale
to it how can I do ?
Locale arrabic= new Locale("ar");
Collator arrabicCollator = Collator.getInstance(arrabic);
Upvotes: 0
Views: 129
Reputation: 20520
Your Comparator
needs to use the Collator
like this:
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());
}
});
for the sorting.
Upvotes: 1