java8 stream sorted

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37880968/article/details/79970003
List<Person> list = Arrays.asList(
new Person(22, "shaomch", "man"),
new Person(26, "mike", "wemon"),
new Person(24, "tom", "wemon"),
new Person(22, "tom", "wemon")
);
//升序排列
List<Person> list1 = list.stream().sorted(Comparator.comparing(Person::getAge)).collect(Collectors.toList());
//降序排列
List<Person> list2 = list.stream().sorted(Comparator.comparing(Person::getAge).reversed()).collect(Collectors.toList());
阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页