当前位置:网站首页>Lambda中间操作flatMap
Lambda中间操作flatMap
2022-06-12 00:36:00 【Leon_Jinhai_Sun】
flatMap
map只能把一个对象转换成另一个对象来作为流中的元素。而flatMap可以把一个对象转换成多个对象作为流中的元素。
例一:
打印所有书籍的名字。要求对重复的元素进行去重。
// 打印所有书籍的名字。要求对重复的元素进行去重。
List<Author> authors = getAuthors();
authors.stream()
.flatMap(author -> author.getBooks().stream())
.distinct()
.forEach(book -> System.out.println(book.getName()));例二:
打印现有数据的所有分类。要求对分类进行去重。不能出现这种格式:哲学,爱情
// 打印现有数据的所有分类。要求对分类进行去重。不能出现这种格式:哲学,爱情 爱情
List<Author> authors = getAuthors();
authors.stream()
.flatMap(author -> author.getBooks().stream())
.distinct()
.flatMap(book -> Arrays.stream(book.getCategory().split(",")))
.distinct()
.forEach(category-> System.out.println(category));边栏推荐
- Gin solves cross domain problems
- How to package and send compressed files for mobile WPS
- 手机wps如何压缩文件打包发送
- Global and Chinese chromatographic silica gel resin industry research and investment direction forecast report 2022 Edition
- [academic related] it is suggested to collect. Which behaviors are academic misconduct?
- 使用 select 切换协程
- Zhangxiaobai takes you to install MySQL 5.7 on Huawei cloud ECS server
- The latest report of Xinsi technology shows that 97% of applications have vulnerabilities
- gin解决跨域问题
- 926. Flip String to Monotone Increasing
猜你喜欢

在玻璃上构建电路

C language exercise: esp32 ble Low Power Bluetooth server data packaging and client data analysis

Experiment 5 constructor and destructor

Detailed explanation of merge sorting

Pycharm file name taboo

How to package and send compressed files for mobile WPS

2022 Tibet's latest eight members (security officer) simulated test question bank and answers

干货|一次完整的性能测试,测试人员需要做什么?

環境搭建2

Why are the values of ordereddict not equal- Why are the values of an OrderedDict not equal?
随机推荐
Sorting out app startup process
Flutter 使用本地图片
926. Flip String to Monotone Increasing
Design principle [Demeter's Law]
2022 edition of global and Chinese sodium hydrosulfide market in-depth investigation and prospect Trend Forecast Report
APP项目怎么测?如何搭建测试体系
The time selector style is disordered and the middle text is blocked
Unified certification center oauth2 high availability pit
設計消息隊列存儲消息數據的 MySQL 錶格
2022 edition of global and Chinese high purity silicon carbide powder operation research and investment strategy analysis report
[flume] notes
Jiaming's day13 of C learning -- structure and structure pointer
设计消息队列存储消息数据的 MySQL 表格
Concevoir une table MySQL pour la mise en file d'attente des messages pour stocker les données des messages
Breadth first search depth first search dynamic programming leetcode topic: delivering information
Global and Chinese maleic anhydride polypropylene industry investment analysis and prospect trend forecast report 2022 Edition
[node] common methods of path module
Cube technology interpretation | detailed explanation of cube applet Technology
汛期化工和危险品企业如何加强防控重大安全风险
苹果手机wps如何改字体大小