崇之他和她

导航

lambda排序list

1.排序list
System.out.println("根据生日降序 (字符串)");
personList = personList.stream().sorted((p1,p2) -> p2.getBirthday().compareTo(p1.getBirthday())).collect(Collectors.toList());
personList.stream().forEach(System.out :: println);
System.out.println("根据年龄升序 (数字)");
personList = personList.stream().sorted((p1,p2) -> p1.getAge().compareTo(p2.getAge())).collect(Collectors.toList());
personList.stream().forEach(System.out :: println);

posted on 2022-04-22 11:25  崇之他和她  阅读(141)  评论(0编辑  收藏  举报