Administrator Mode

No good address book sorting method recommended

146 4

There's no good address book sorting method recommended for java background.

High efficiency, as shown below, ~ ~.

1 Answers

102 0

Convert names to pinyin by using pinyin4j

And then we use the str. Dca ( ) to sort the ei.

 Collections.sort(commoditiesFilter, new Comparator<Commodity>() {
 @Override
 public int compare(Commodity o1, Commodity o2) {
 String name1 = null;
 String name2 = null;
 try {
 name1 = PinyinUtils.getPinyinOfHanyu(o1.getName());
 name2 = PinyinUtils.getPinyinOfHanyu(o2.getName());
 } catch (BadHanyuPinyinOutputFormatCombination e) {
 e.printStackTrace();
 }
 return name1.compareTo(name2);
 }
 });
...