当前位置:网站首页>Lambda end operation collect
Lambda end operation collect
2022-06-13 03:48:00 【Leon_ Jinhai_ Sun】
collect
Convert the current stream into a collection .
Example :
Get a file that holds the names of all authors List aggregate .
// Get a file that holds the names of all authors List aggregate .
List<Author> authors = getAuthors();
List<String> nameList = authors.stream()
.map(author -> author.getName())
.collect(Collectors.toList());
System.out.println(nameList);
Get a list of all book titles Set aggregate .
// Get a list of all book titles Set aggregate .
List<Author> authors = getAuthors();
Set<Book> books = authors.stream()
.flatMap(author -> author.getBooks().stream())
.collect(Collectors.toSet());
System.out.println(books);
Get one Map aggregate ,map Of key Name the author ,value by List<Book>
// Get one Map aggregate ,map Of key Name the author ,value by 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);
边栏推荐
- Fundamentals of robot obstacle avoidance system
- CDN domain name
- Workflow of driver of spark kernel (stage division, task division, task scheduling)
- footstep
- 双目视觉——打造室外避障的“最优解”
- How much can I get after the insurance period of annuity insurance products expires?
- 【面试复习】自用不定时更新
- 【 développement d'essais 】 sélénium d'essais automatisés (Ⅲ) - - analyse du cadre unitest
- The latest summary of key topics of journal C in 2022 - topic scope, contribution method and journal introduction
- UnionPay commerce - merchant statistics service platform
猜你喜欢
单片机:PCF8591 应用程序
The latest summary of key topics of journal C in 2022 - topic scope, contribution method and journal introduction
MySQL 8.0 enables remote root user access and solves the problem of you are not allowed to create a user with Grant
LVS四层负载均衡集群(4)负载均衡的主要方式
Synching build your own synchronization cloud
单片机:A/D 差分输入信号
单片机:A/D 和 D/A 的基本概念
[test development] automated test selenium (III) -- unittest framework analysis
【测试开发】进阶篇——各种测试技术分类
Spark Optimization -- differences and policy selection of RDD cache (cache, persist, checkpoint)
随机推荐
Workflow of driver of spark kernel (stage division, task division, task scheduling)
Advanced API review
leetcode.1 --- 两数之和
How much can I get after the insurance period of annuity insurance products expires?
Byte stream & buffer stream
LVS四层负载均衡集群(4)负载均衡的主要方式
C language programming -- input a string (including letters, numbers, punctuation marks, and space characters) from the keyboard, calculate the actual number of characters and print out, that is, it d
四旋翼飞行器避障系统基础
Express 100
Window and various windowfunctions in Flink
手机私有充电协议解读
单片机:I2C通信协议讲解
【 développement d'essais 】 sélénium d'essais automatisés (Ⅲ) - - analyse du cadre unitest
Determine whether the file encoding format is UTF-8 or GBK
Understand the difference between reducebykey and groupbykey in spark
单片机/嵌入式的实时性疑问解答
Installing MySQL 8.0.20 under Linux and ubuntu20.04 LTS
单片机串口通信原理和控制程序
LVS四層負載均衡集群(3)集群功能分類 - HPC
机器人避障系统基础