- public class AlphabetComparator implements Comparator<String> {
- private RuleBasedCollator collator;
- public AlphabetComparator() {
- collator = (RuleBasedCollator) Collator
- .getInstance(java.util.Locale.CHINA);
- }
- @Override
- public int compare(String obj1, String obj2) {
- CollationKey c1 = collator.getCollationKey(obj1);
- CollationKey c2 = collator.getCollationKey(obj2);
- return collator.compare(((CollationKey) c1).getSourceString(),
- ((CollationKey) c2).getSourceString());
- }
- }
- AlphabetComparator cfc = new AlphabetComparator();
- Collections.sort([需要排序的数据], cfc);