I have some classes like below:
Class A {
    private String name;
    private List<B> b;
    // getters and setters
}
Class B {
    private String name;
    private List<C> c;
    // getters and setters
}
Class C {
    private String name;
    private List<D> d;
    // getters and setters
}
Class D {
    // properties
    // getters and setters
}
Now I have a list of type A. What I want to do is to get a list containing other lists of type D like this:
List<List<D>>
I have tried somthing like this using flatMap:
listA.stream()
     .flatMap(s -> s.getB.stream())
     .flatMap(s -> s.getC.stream())
     .flatMap(s -> s.getD.stream())
     .collect(Collectors.toList());
But this collects all the elements of type D into a list:
List<D>
Can someone help please?
 
     
    