I need go through a list(class A) from lists(classB). I want to use streams JAVA8, but go through the second list i lose the reference from first list
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
});
The error is "cannot find simbol variable a" I understand the error, There is any solutions use streams and not foreach or for loop?