java 城市按照首字母拍讯

 javalist对象进行城市的排序

    HanyuPinyinOutputFormat pinyinOutputFormat = new HanyuPinyinOutputFormat();
Collections.sort(collect, (MyBusinessUnitDto info1, MyBusinessUnitDto info2)-> {
                    String province1 = null;
                    String province2 = null;
                    try {
                        province1 = PinyinHelper.toHanYuPinyinString(info1.getCompanyFullName(), pinyinOutputFormat, " ", true);
                        province2 = PinyinHelper.toHanYuPinyinString(info2.getCompanyFullName(), pinyinOutputFormat, " ", true);
                    } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
                       log.info("汉字排序错误: {}",badHanyuPinyinOutputFormatCombination.getMessage());
                    }
                    return Optional.ofNullable(province1).orElse("").compareTo(province2);
                }
            );

 maven配置

    
            com.belerweb
            pinyin4j
            2.5.1
        

 

你可能感兴趣的:(java后端开发,java)