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());
在分組時,將映射的對象轉成其他值,默認用Collectors.toList()代替Collectors.mapping()
Map<String, List<String>> tableMap = tableList.stream().collect(Collectors.groupingBy(TableDTO::getDbName, Collectors.mapping(TableDTO::getTableName, Collectors.toList())));