一、通过Stream流进行汉字排序:
Comparator<Object> comparator = Collator.getInstance(java.util.Locale.CHINA); CompanyPhonesDto companyPhonesDto = new CompanyPhonesDto(); List<String> companyName = new ArrayList<>(); // 数据列表(查询语句) List<InsuranceCompany> companies = insuranceCompanyService.list(); // 汉字排序 companies = companies.stream().sorted((p1, p2) -> comparator.compare(p1.getCompanyName(), p2.getCompanyName())).collect(Collectors.toList());
二、提取汉字首字母
2.1 :引入maven
<!-- pinyin4j --> <dependency> <groupId>com.belerweb</groupId> <artifactId>pinyin4j</artifactId> <version>2.5.1</version> </dependency>