如何使用FlatMap列表从流中获取<>列表的项目
我有一个DTO(POJO)的集合。
Collection<Dto> dtos = new ArrayList<>();
... <filling dto> now it has items.
DTO有一个字段列表:
class Dto {
private List<Tag> tags;
}
@RequiredArgsConstructor
class Tag {
private String name;
}
数据的示例:
dtos.get(1) => new Tag('name1.1') -> new Tag('name1.2')
dtos.get(2) => new Tag('name2.1')
dtos.get(3) => new Tag('name3.1') > new Tag('name3.2')
dtos.get(4) => null
一个问题L如何仅使用流java8+所有列表 是否可以使用FlatMap() ?
您的想法
I have a Collection of a Dto (Pojo).
Collection<Dto> dtos = new ArrayList<>();
... <filling dto> now it has items.
Dto has a field List:
class Dto {
private List<Tag> tags;
}
@RequiredArgsConstructor
class Tag {
private String name;
}
Example of Data:
dtos.get(1) => new Tag('name1.1') -> new Tag('name1.2')
dtos.get(2) => new Tag('name2.1')
dtos.get(3) => new Tag('name3.1') > new Tag('name3.2')
dtos.get(4) => null
a QUESTIONL How to get using only stream Java8+ all List
is it possible to use flatMap()
You ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这应该很简单,您过滤
null
标签,然后flatmap
他们,收集
列表I think this should be straightforward, you filter the
null
tags thenflatmap
them andcollect
to a list