Java中Stream流里面的findFirst()和findAny()區別


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())));

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM