title: Java 8 collecting the list that is already present in object
body: <p>I was just searching for better way to handle this scenario using java 8 streams. Object A has list of object b. What I get is a list of object A (List). I need to stream through list of object A and get all the listB's in each of the object A as a one single list. </p>
  
  <pre><code>class A {
      List&lt;B&gt; listB
  }
  </code></pre>
  
  <p>I have tried the below way it throws compilation</p>
  
  <pre><code>List&lt;A&gt; as = someObject.getAs();
  List&lt;B&gt; listofBs = as.stream().map(in -&gt; in.getListB()).collect(Collectors.toList());
  </code></pre>