title: Getting the hashmap values of an object list using lambdas
body: <p>Lets assume I have an object:</p>
  
  <pre><code>class MyObject {
      private int id;
      private HashMap&lt;Integer, OtherObject&gt; otherObjects;
  }
  </code></pre>
  
  <p>What I want to do is access the <code>otherObjects</code> property of a list of <code>MyObject</code> and add them all to a <code>otherObjects</code> <code>list</code>.</p>
  
  <p>I could use a <code>.forEach</code> and <code>.addAll</code> into the <code>otherObjects</code> <code>list</code> but I'm trying see if it is possible to use lambdas to achieve this. I thought of something like this but it doesn't seem to work:</p>
  
  <pre><code>myObjectList.stream()
      .map(o -&gt; o.getOtherObjects())
      .map(oo -&gt; oo.values())
      .collect(Collectors.toList());
  </code></pre>
  
  <p>But there seems to be a conflict with the object types. I'm guessing it is because I start with a stream of objects and end up with a stream of lists and it gets confused. How can I achieve this? And more generally, how can I gather a list of objects of many parent objects into a single list?</p>