当前位置:网站首页>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);
边栏推荐
- 测试写入mysql数据300W条,每次1.6-2W之间就断掉然后出现以下问题:
- Simulink code generation: simple state machine and its code
- Pollution discharge fees of listed companies 2010-2020 & environmental disclosure level of heavy pollution industry - original data and calculation results
- Alipay open platform
- Understand the difference between reducebykey and groupbykey in spark
- ONNX+TensorRT+YoloV5:基于trt+onnx得yolov5部署1
- C语言程序设计——从键盘任意输入一个字符串(可以包含:字母、数字、标点符号,以及空格字符),计算其实际字符个数并打印输出,即不使用字符串处理函数strlen()编程,但能实现strlen()的功能。
- China Civil Aviation Statistical Yearbook (1996-2020)
- 【MySQL】索引与事务
- Batch image Download & socket dialogue
猜你喜欢
Workflow of driver of spark kernel (stage division, task division, task scheduling)
Understand the difference between reducebykey and groupbykey in spark
Coal industry database - coal price, consumption, power generation & Provincial Civil and industrial power consumption data
Domestic zynq standalone pl-ps interrupt commissioning
LVS four - tier Load Balancing Cluster (5) LVS Overview
LVS four layer load balancing cluster (6) LVS working mode
Brief introduction: distributed cap theory and base theory
Alipay open platform
User and permission configuration in SQL Server database to ensure database security
2000-2019 enterprise registration data of all provinces, cities and counties in China (including longitude and latitude, registration number and other multi indicator information)
随机推荐
Coal industry database - coal price, consumption, power generation & Provincial Civil and industrial power consumption data
Spark optimization - data skew solution
(九)详解广播机制
Masa auth - SSO and identity design
Summary of the latest rail transit (Subway + bus) stops and routes in key cities in China (II)
Use of Oracle PL-SQL
MySQL learning summary 8: addition, deletion and modification of data processing
【多线程】多线程到底是个甚——多线程初阶(复习自用)
Azure SQL db/dw series (12) -- using query store (1) -- report Introduction (1)
Economic panel topic 1: panel data of all districts and counties in China - more than 70 indicators such as population, pollution and agriculture (2000-2019)
MASA Auth - 从用户的角度看整体设计
Determine whether the file encoding format is UTF-8 or GBK
【youcans 的 OpenCV 例程200篇】201. 图像的颜色空间转换
Review the first three IO streams
【Web】Cookie 和 Session
Database object, sequence, view, index
2016. maximum difference between incremental elements
Oracle built-in functions
【测试开发】软件测试基础篇
MySQL learning summary 6: data type, integer, floating point number, fixed-point number, text string, binary string