【发布时间】:2015-01-16 14:52:05
【问题描述】:
我有对象列表
List<FrameworkAdminLeftMenu> menu = getMenuFromDB();
每个FrameworkAdminLeftMenu 对象都有方法
public Set<FrameworkAdminLeftMenuCategories> getFrameworkAdminLeftMenuCategorieses() {
return this.frameworkAdminLeftMenuCategorieses;
}
和方法
public String getCssClassName() {
return this.cssClassName;
}
每个FrameworkAdminLeftMenuCategories 对象都有方法
public Integer getId() {
return this.id;
}
如何过滤所有 List 和 Set 以通过 getId(1) 获取 FrameworkAdminLeftMenuCategories 对象?
例如,像
List<FrameworkAdminLeftMenu> collect = menu.stream()
.filter(
f -> f
.getCssClassName()
.contains("adm-content")
)
.collect(Collectors.toList());
List<FrameworkAdminLeftMenuCategories> categs = collect
.stream()
.filter(
f -> f.
getFrameworkAdminLeftMenuCategorieses()
.stream()
.filter(c -> c.getId() == 1)
)
.collect(Collectors.toList());
【问题讨论】:
-
“Categorieses”复数的复数? :-)
-
不完全确定你在问什么。您是否想要从具有该 ID 的所有集合中收集所有类别的集合?在这种情况下,请尝试
flatMap
标签: java java-stream