将Integer集合 转换为String集合
Set<String> userIDs = userByUserID.stream().map(TUser::getID).map(Functions.toStringFunction()).collect(Collectors.toSet());
这样可以取到对象里面的最大值
Optional<TUserReport> report = reported.stream().collect(Collectors.maxBy(Comparator.comparing(TUserReport::getPostTime)));
Integer maxValue = songResultDemos.stream().map(SongResultDemo::getSongNum).max(Integer::compareTo).get();
这样可以一list集合里面的对象的一个字段 为key value 就是 整个对象并且是个list集合
Map<Integer, List<TUserReport>> reportedUserMapList = all.stream().collect(Collectors.groupingBy(TUserReport::getUserId));
将id 与 对象装入一个map集合 id对应的就是它的对象
Map<Integer, TAccount> allAccountIDMap = allAccountIDList.stream().collect(Collectors.toMap(TAccount::getId, Function.identity()));
获取到用户id的集合
Set<Integer> accountIDSet = topicByAccountAndTypeAndTime.stream().map(TTopicFeedOperateRecord::getAccountId).collect(Collectors.toSet());
排序的 一种方法
userReportDTOS.sort(Comparator.comparing(UserReportDTO::getPostTime).reversed());
双重排序
userReportVos.sort(Comparator.comparing(UserReportVo::getReportCount).thenComparing(UserReportVo::getLastReportTime).reversed());
分页
List<FeedVo> limitvos = productFeed.stream().skip((currentPage - 1) * 10).limit(10).collect(Collectors.toList());
过滤
List<LinkNameVo> collect = linkNameVos.stream().filter(linkNameVo -> auditorAndAuditeeList.stream().noneMatch(e -> e.equals(linkNameVo.getId()))).collect(Collectors.toList());
去掉对象集合里面有相同字段的对象
List<QualityTeamVo> collect1 = qualityTeamVos.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(QualityTeamVo::getDepartmentName))), ArrayList::new));
过滤出第一个 并且有两个条件
AliGreenVo aliGreenVo = aliGreenVoList.stream().filter(aliGreen -> "review".equals(aliGreen.getSuggestion()) ||
"block".equals(aliGreen.getSuggestion())).findFirst()
.orElse(new AliGreenVo(null, null, "normal", "pass", null));
将集合里面的某个字段 相同的去除
List<TBigvList> collect = accountNickname1.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(f -> f.getAccountNickname()))), ArrayList::new));
获取对象里所有 level 等于 3的 对象
List<ShowProjectVo> third = result.stream().filter(s -> Integer.valueOf(3).equals(s.getLevel())).collect(Collectors.toList());