【发布时间】:2019-06-21 20:01:20
【问题描述】:
我需要通过列表(B 类)中的一个列表(A 类)。我想使用流 JAVA8,但是通过第二个列表我失去了第一个列表的引用
class A {
Collection<B> listB ;
String x;
// Some other variables
}
class B {
String y;
// Some other variables
}
// List object A
Collection<class A> listA;
listA.stream()
.filter(a -> a.getListaB() != null)
.flatMap(a -> a.getListB().stream())
.forEach(b -> {
// Here lose reference object A
// I need something like a.getX()
// I need too use something like b.getY(), use both lists
});
错误是“找不到simbol变量a”我理解错误,有没有使用流而不是foreach或for循环的解决方案?
【问题讨论】:
标签: list java-8 java-stream