Java使用Collections對中文字元進行首字母排序

梵蒂岡士大夫發表於2020-12-13
  // 按照首字母排序
                        Collections.sort(dataList, new Comparator<StoreGoodsConfig>() {
                            Collator collator = Collator.getInstance(Locale.CHINESE);
                            @Override
                            public int compare(StoreGoodsConfig o1, StoreGoodsConfig o2) {
                                return collator.getCollationKey(o1.name).compareTo(collator.getCollationKey(o2.name));
                            }
                        });

 

相關文章