分组
Map<String, List<pre>> res = list.stream().collect(Collectors.groupingBy(pre::getSex));
排序
正序
List<Integer> res = list.stream().sorted().collect(Collectors.toList());
正序
List<pre> res=list.stream().sorted(Comparator.comparing(pre::getAge)).collect(Collectors.toList());
倒序
List<pre> sortReverseRlt=list.stream().sorted(Comparator.comparing(pre::getAge).reversed()).collect(Collectors.toList());
去重
List<pre> collect = list.stream().distinct().collect(Collectors.toList());
通过条件过滤
将 strings 集合中带 f 的字符串筛选出来放如另外一个集合
List<String> filterStrings = strings.stream().filter(str -> str.contains("f")).collect(Collectors.toList());
将 students 集合中叫年龄为 18 的同学找出来
List<Student> filterStudents = students.stream().filter(student -> 18 == student.getAge()).collect(Collectors.toList());