1. 判断集合中的某个元素的某个属性是否全部相等
List<User> users = new ArrayLiat<>();
long count = users.stream().map(User::getAge).distinct().count();
2. 根据对象中某个元素进行分组
List<User> users = new ArrayLiat<>();
Map<String,List<User>> map = users .stream().collect(Collectors
.groupingBy(User::getUserCode));
3.根据集合对象中的某个元素去重
List<Student> studentList = new ArrayList<>();
studentList.add(new Student("1","小c","18"));
studentList.add(new Student("2","小b","18"));
studentList = studentList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Student :: getAge))), ArrayList::new));
4.根据集合对象中某个元素排序
studentList .stream().sorted(Comparator.comparing(Student::getAge).reversed()).collect(Collectors.toList());
studentList .stream().sorted(Comparator.comparing(Student::getAge)).collect(Collectors.toList());
list = list.stream().sorted(Comparator.comparing(e -> e.getAge())).collect(Collectors.toList());
list = list.stream().sorted(Comparator.comparing(Student::getAge).thenComparing(Comparator.comparing(Student::getScore))).collect(Collectors.toList());
list 去重
list = list.stream().distinct().collect(Collectors.toList())
list转换.
List<OmpInterfaceVersionResDO> twoLevelSubjects = ListBeanUtils.copyListProperties(lists, OmpInterfaceVersionResDO::new);