当前位置:网站首页>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));边栏推荐
- JS -- prevent automatic recovery of page position
- [node] common methods of path module
- Mathematical modeling experience ----- summary of three modeling
- Experiment 6 constructor + copy construction
- The "hard words" about interface testing
- Design principle [Demeter's Law]
- Matplotlip basic drawing learning of data analysis - 01
- 2023 spring recruit | ant group middleware Intern Recruitment
- Devops landing practice drip and pit stepping records - (1)
- How to cancel smart table style in WPS table
猜你喜欢

Pre resolution and scope

IP编址概述

win10系统pscs6如何卸载

At the digital data nextionbi online conference, traditional enterprises showed their in-depth understanding of data analysis
![[industry application] an article on power digital transformation](/img/4a/d2d2795992cac8fb76135a117c3091.jpg)
[industry application] an article on power digital transformation

Jeecgboot 3.1.0 release, enterprise low code platform based on code generator

Streaming Data Warehouse 存储:需求与架构

ironSource&nbsp; New functions are released, and developers can adjust advertising strategies in real time in the same session

Wechat applet Chinese English conversion

Unified certification center oauth2 high availability pit
随机推荐
Understanding of black box testing by novices after years of testing
What does the Red Cross of win10 folder status indicate
Tianjin Port coke wharf hand in hand map flapping software to visually unlock the smart coke port
2021 inventory: Top 10 low code development platforms at home and abroad
[flume] notes
Bgfx multithreaded rendering
在玻璃上构建电路
win7 fps优化的方法
使用 select 切换协程
IP addressing overview
Do you want to take the postgraduate entrance examination? Will you be able to find a good job after graduate school?
Jeecgboot 3.1.0 release, enterprise low code platform based on code generator
Zhangxiaobai takes you to install MySQL 5.7 on Huawei cloud ECS server
Current situation investigation and demand forecast report of global and Chinese phenolic resin market, 2022 Edition
Redis advanced - correspondence between object and code base
Detailed explanation of merge sorting
Dry goods | what do testers need to do for a complete performance test?
Invalid spacing setting before WPS Title segment solution
gin解决跨域问题
Breadth first search depth first search dynamic programming leetcode topic: delivering information