标签:
1 public abstract class Collator implements Comparator<Object>, Cloneable{}
1 /** 2 * Returns a {@code Collator} instance which is appropriate for the user‘s default 3 * {@code Locale}. 4 * See "<a href="../util/Locale.html#default_locale">Be wary of the default locale</a>". 5 */ 6 public static Collator getInstance() { 7 return getInstance(Locale.getDefault()); 8 }
1 /** 2 * Returns a {@code Collator} instance which is appropriate for {@code locale}. 3 */ 4 public static Collator getInstance(Locale locale) { 5 if (locale == null) { 6 throw new NullPointerException("locale == null"); 7 } 8 return new RuleBasedCollator(new RuleBasedCollatorICU(locale)); 9 }
1 public class CompareHelper { 2 3 public static final Collator COLLATOR = Collator.getInstance(); 4 5 public static final Comparator<Contact> COMPARATOR_CONTACT; 6 7 static 8 { 9 COMPARATOR_CONTACT = new Comparator<Contact>(){ 10 public final int compare(Contact a, Contact b){ 11 return COLLATOR.compare(a.sortKeyString, b.sortKeyString); 12 } 13 }; 14 } 15 private CompareHelper(){} 16 }
2.对List元素进行重新排序:
1 Collections.sort(contacts, CompareHelper.COMPARATOR_CONTACT);
标签:
原文地址:http://www.cnblogs.com/carbs/p/5312462.html