当前位置:网站首页>Lambda终结操作collect
Lambda终结操作collect
2022-06-13 03:35:00 【Leon_Jinhai_Sun】
collect
把当前流转换成一个集合。
例子:
获取一个存放所有作者名字的List集合。
// 获取一个存放所有作者名字的List集合。
List<Author> authors = getAuthors();
List<String> nameList = authors.stream()
.map(author -> author.getName())
.collect(Collectors.toList());
System.out.println(nameList);获取一个所有书名的Set集合。
// 获取一个所有书名的Set集合。
List<Author> authors = getAuthors();
Set<Book> books = authors.stream()
.flatMap(author -> author.getBooks().stream())
.collect(Collectors.toSet());
System.out.println(books);获取一个Map集合,map的key为作者名,value为List<Book>
// 获取一个Map集合,map的key为作者名,value为List<Book>
List<Author> authors = getAuthors();
Map<String, List<Book>> map = authors.stream()
.distinct()
.collect(Collectors.toMap(author -> author.getName(), author -> author.getBooks()));
System.out.println(map);边栏推荐
- Local simulation download file
- The latest summary of key topics of journal C in 2022 - topic scope, contribution method and journal introduction
- Summary of the latest rail transit (Subway + bus) stops and routes in key cities in China (II)
- ONNX+TensorRT+YoloV5:基于trt+onnx得yolov5部署1
- Watering artifact based on Huawei cloud Internet of things (stm32+esp8266)
- A data modeling optimization solution for graph data super nodes
- On interests and hobbies
- Solve the error in CONDA installation PyMOL
- Complete set of Stata code commands: follow and verify do files, common Stata commands, code collection, panel entropy method
- Panel for measuring innovation efficiency of 31 provinces in China (using Malmquist method)
猜你喜欢

基于华为云物联网设计的浇花神器(STM32+ESP8266)

Panel for measuring innovation efficiency of 31 provinces in China (using Malmquist method)

Environmental pollution, enterprises, highways, fixed assets, foreign investment in all prefecture level cities in China - latest panel data

Domestic zynq standalone pl-ps interrupt commissioning

【MySQL】索引与事务

【測試開發】自動化測試selenium(三)——unittest框架解析

User and permission configuration in SQL Server database to ensure database security
![[test development] automatic test selenium (I)](/img/cd/b6dc4ac53b4f30f745ec0590ac384b.png)
[test development] automatic test selenium (I)

An error is reported in the JDBC connection database: connection to 139.9.130.37:15400 referred

Azure SQL db/dw series (9) -- re understanding the query store (2) -- working principle
随机推荐
Masa Auth - SSO and Identity Design
CDN domain name
ip地址及分类
Masa auth - SSO and identity design
What to bring to 2022
基于华为云物联网设计的浇花神器(STM32+ESP8266)
MySQL 8.0 enables remote root user access and solves the problem of you are not allowed to create a user with Grant
在JDBC连接数据库时报错:Connection to 139.9.130.37:15400 refused.
Installing MySQL 8.0.20 under Linux and ubuntu20.04 LTS
CXGRID keeps the original display position after refreshing the data
User and permission configuration in SQL Server database to ensure database security
[azure data platform] ETL tool (6) -- re understanding azure data factory
LVS four layer load balancing cluster (4) main methods of load balancing
Masa auth - overall design from the user's perspective
MySQL learning summary 6: data type, integer, floating point number, fixed-point number, text string, binary string
【测试开发】博客系统——Loadrunner性能测试(发布博客功能 基准测试)
Azure SQL db/dw series (12) -- using query store (1) -- report Introduction (1)
Three ways of scala string interpolation
Get to know druid IO real time OLAP data analysis storage system
Onnx+tensorrt+yolov5: yolov5 deployment based on trt+onnx 1