findFirst()和findAny()存在并行上的区别,findFirst并行限制较多,findAny并行限制较少,如果不在乎哪个值,用findAny。

两个list列表用stream流进行过滤:

List<ChangeRecordListDTO> filteredList = allList.stream().filter(t -> recordList.stream().filter(s -> t.getId().longValue() == s.getManagerId()).findFirst().orElse(null) != null).collect(Collectors.toList());

在分组时,将映射的对象转成其他值

Map<String, List<String>> tableMap = tableList.stream().collect(Collectors.groupingBy(TableDTO::getDbName, Collectors.mapping(TableDTO::getTableName, Collectors.toList())));

在分组时,将映射的对象转成其他值,默认用Collectors.toList()代替Collectors.mapping()

Map<String, List<String>> tableMap = tableList.stream().collect(Collectors.groupingBy(TableDTO::getDbName, Collectors.mapping(TableDTO::getTableName, Collectors.toList())));