、
Student student = new Student();
student.setId(10l);
student.setUserId(10L);
student.setAge(10);
student.setName(“班级1”);
student.setClassId(1);
Student student1 = new Student();
student1.setId(11l);
student1.setUserId(111L);
student1.setAge(11);
student1.setName("班级1");
student1.setClassId(1);
Student student2 = new Student();
student2.setId(12l);
student2.setUserId(12L);
student2.setAge(12);
student2.setName("班级2");
student2.setClassId(2);
Student student3 = new Student();
student3.setId(12l);
student3.setUserId(19L);
student3.setAge(19);
student3.setName("班级2");
student3.setClassId(3);
//获取所有id的集合
List<Student> students = Arrays.asList(student, student1, student2, student3);
List<Long> collect = students.stream().map(Student::getId).collect(Collectors.toList());
System.out.println(collect);
//获取所有age的k=>v
Map<Integer, Student> collect1 = students.stream().collect(Collectors.toMap(Student::getAge, a -> a, (v1, v2) -> v2));
System.out.println(collect1);
//根据classId分组
Map<Integer, List<Student>> collect2 = students.stream().collect(Collectors.groupingBy(Student::getClassId));
System.out.println(collect2);
//根据年龄排序
students.stream().sorted((a1,a2)->a1.getAge()-a2.getAge()).collect(Collectors.toList());
students.sort((Student t1,Student t2)->t1.getAge().compareTo(t2.getAge()));