8

I am trying to concat list of a stream and process it.

class A {
    public List<B> bList;
}
List<A> aList;
aList.stream().map(a -> a.bList)....

Here i get several list of b.

But, I would like to collect all my b in only one list. Any ideas ?

Stuart Marks
  • 120,620
  • 35
  • 192
  • 252
Clem
  • 1,862
  • 14
  • 17

1 Answers1

18

That's what flatMap is for :

List<B> bList = aList.stream()
                     .flatMap(a -> a.bList.stream())
                     .collect(Collectors.toList());
Eran
  • 374,785
  • 51
  • 663
  • 734