实现中文首字母排序
@Test
public void test1() {
//实现中文首字母排序
List<Dto> list = Arrays.asList(new Dto("鲍勃", 16), new Dto("艾琳", 18), new Dto("蔡依林", 19));
Comparator comparator = Collator.getInstance(Locale.CHINA);
Collections.sort(list, (o1, o2) -> comparator.compare(o1.getName(), o2.getName()));
System.out.println(list);
//[TestMain.Dto(name=艾琳, age=18), TestMain.Dto(name=鲍勃, age=16), TestMain.Dto(name=蔡依林, age=19)]
}
@Data
@AllArgsConstructor
class Dto {
private String name;
private Integer age;
}