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 @ 2022-04-22 11:25  崇之他和她  阅读(149)  评论(0)    收藏  举报

作者:{author}

出处:{post_url}

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。