当前位置:网站首页>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));边栏推荐
- LabVIEW Arduino电子称重系统(项目篇—1)
- 功能测试如何1个月快速进阶自动化测试?明确这2步就问题不大了
- Adult education online training website open source
- Streaming Data Warehouse 存储:需求与架构
- 2022 Tibet's latest eight members (security officer) simulated test question bank and answers
- 730.Count Different Palindromic Subsequences
- Investment analysis and prospect Trend Research Report of global and Chinese cyclopentanyl chloride industry 2022-2028
- Devops landing practice drip and pit stepping records - (1)
- Zhangxiaobai takes you to install MySQL 5.7 on Huawei cloud ECS server
- Two configurations of data tables in efcore
猜你喜欢

Visitors push e-commerce express without tossing about personal payment codes

LabVIEW Arduino电子称重系统(项目篇—1)

The latest report of Xinsi technology shows that 97% of applications have vulnerabilities

Characteristics of JS logical operators

DPT-FSNET: DUAL-PATH TRANSFORMER BASED FULL-BAND AND SUB-BAND FUSION NETWORK FOR SPEECH ENHANCEMENT

一、Flutter 入门学习写一简单客户端

点云库pcl从入门到精通学习记录 第八章

Seven trends in test automation that need attention

Cuiyunkai, CEO of Gewu titanium Intelligent Technology: data value jump, insight into the next generation of change forces

Is the o2o platform worth doing in 2022
随机推荐
How to package and send compressed files for mobile WPS
Anfulai embedded weekly report (issue 254): February 21, 2022 to February 27, 2022
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
Detailed explanation of merge sorting
Experiment 7 class construction and static member function
Share an open source, free and powerful video player library
Redis master-slave replication, sentinel mode and cluster
C语言练习:ESP32 BLE低功耗蓝牙服务端数据打包和客户端数据解析
苹果手机wps如何改字体大小
Investment analysis and demand forecast report of global and Chinese fluorosilicone industry in 2022
Understanding of black box testing by novices after years of testing
Flutter 使用本地图片
Exploration of qunar risk control safety products
Experiment four categories and objects
Investment analysis and prospect Trend Research Report of global and Chinese cyclopentanyl chloride industry 2022-2028
How to change the font size of Apple phone WPS
Optimization method of win7 FPS
Cube technology interpretation | detailed explanation of cube applet Technology
730.Count Different Palindromic Subsequences