title: Lambda & Stream : collect in a Map
body: <p>I would like to build a Map using the Stream &amp; Lambda couple.</p>
  
  <p>I've tried many ways but I'm stucked. Here's the classic Java code to do it using both Stream/Lambda and classic loops.</p>
  
  <pre><code>Map&lt;Entity, List&lt;Funder&gt;&gt; initMap = new HashMap&lt;&gt;();
  List&lt;Entity&gt; entities = pprsToBeApproved.stream()
      .map(fr -&gt; fr.getBuyerIdentification().getBuyer().getEntity())
      .distinct()
      .collect(Collectors.toList());
  
  for(Entity entity : entities) {
      List&lt;Funder&gt; funders = pprsToBeApproved.stream()
          .filter(fr -&gt; fr.getBuyerIdentification().getBuyer().getEntity().equals(entity))
          .map(fr -&gt; fr.getDocuments().get(0).getFunder())
          .distinct()
          .collect(Collectors.toList());
      initMap.put(entity, funders);
          }
  </code></pre>
  
  <p>As you can see, I only know how to collect in a list, but I just can't do the same with a map. That's why I have to stream my list again to build a second list to, finally, put all together in a map.
  I've also tried the 'collect.groupingBy' statement as it should too produce a map, but I failed.</p>