1 从list中快速取出对象的某个属性值
List clientDTOS = entityMapper.clientBorrowersToDTO(list);
List ids = clientDTOS.stream().map(ClientDTO::getClientId).collect(Collectors.toList());
2 按照条件取出数据
List users = sysUserService.listUserByRole(nextRoleName);
users = users.stream().filter(e -> e.getPosition().equals("主管")).collect(Collectors.toList());
3 提取出list对象中的一个属性
List stIdList1 = stuList.stream().map(Person::getId).collect(Collectors.toList());
4 提取出list对象中的一个属性并去重
List stIdList2 = stuList.stream().map(Person::getId).distinct().collect(Collectors.toList());
5 按照某个字段去重得到list对象
ArrayList collect = result.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SysDepartment::getId))), ArrayList::new));
6 (根据年级和专业,当年级和专业都相同的情况下看做是重复数据)
List distinctClass = classEntities.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getProfessionId() + ";" + o.getGrade()))), ArrayList::new));
7 通过hashSet去重(如将classNames去重):该种去重是bean完全相同的时候算重复数据
List classNameList = new ArrayList(new HashSet(classNames));
8 获取最小值
roleList.stream().mapToInt(SysRole -> SysRole.getDataPermission()).min().getAsInt();
9 排序 降序输出
List studentsSortName = studentList.stream().sorted(Comparator.comparing(StudentInfo::getAge).reversed()).collect(Collectors.toList());
List candidateUserIds = sysUsers.stream().map(SysUser::getId).map(String::valueOf).collect(Collectors.toList());
list.stream().mapToDouble(Student1::getScore).sum()//和
list.stream().mapToDouble(Student1::getScore).max()//最大
list.stream().mapToDouble(Student1::getScore).min()//最小
list.stream().mapToDouble(Student1::getScore).average()//平均值
10 BigDecimal属性求和
BigDecimal reduce = plans.stream().filter(x -> x.getSurplusAmonunt().compareTo(new BigDecimal(0)) != 0).map(RepayPlan::getSurplusAmonunt).reduce(BigDecimal.ZERO, BigDecimal::add);
11 打印
list.stream().filter((s) -> s.startsWith("a")).forEach(System.out::println); //aaa,过滤开始元素为a的字符串。
12 count()操作
long count = list.stream().filter((user) -> user.getName().startsWith("a")).count();



