JAVA8中的stream排序
Student user1 = new Student(21,"张三");
Student user2 = new Student(25,"李四");
Student user3 = new Student(22,"王五");
Student user4 = new Student(19,"赵柳");
List<Student> list = new ArrayList<Student>();
list.add(user1);
java streamlist.add(user2);
list.add(user3);
list.add(user4);
for(Student u :list){
System.out.println(u);
}
List<Student> newList = list.stream().sorted(Comparatorparing(Student::getAge).reversed()).List()); reversed()指根据getAge进⾏倒序排序。
System.out.println(list.stream().map(e -> e.getAge()).List()));
System.out.println(list.stream().map(Student::getAge).List()));
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论