title: Use streams to group Map<Foo,List<Bar>> based on size of the List<Bar>
body: <p>I'm trying to transform data of this format:</p>
  
  <pre><code>Map&lt;Foo, List&lt;Bar&gt;&gt; mapFooToBars;         //start Map
  Map&lt;Integer, List&lt;Foo&gt;&gt; mapListSizeToFoos //destination Map
  </code></pre>
  
  <p>I'd like to create a grouping based on the size of the <code>List&lt;Bar&gt;</code> for each entry, so that in my output map, I would have a list of all Foos that have 0 Bars together, all Foos that have 1 Bar together, and so on.</p>
  
  <p>I was trying to do this:</p>
  
  <pre><code>Map&lt;Foo, List&lt;Bar&gt;&gt; fooBarMap = whatever();
  fooBarMap.entrySet().stream()
      .collect(Collectors.groupingBy(entry -&gt; entry.getValue().size()));
  //expected Map&lt;Integer,Entry&lt;Foo, List&lt;Bar&gt;&gt; which
  //could be transformed into Map&lt;Integer,Foo&gt; pretty easily
  </code></pre>
  
  <p>I apparently am unclear on how groupingBy works exactly, as this is giving me a "getValue() is undefined for the type Object" error. Somewhere along the line I'm losing the type information about entrySet I guess? It made me wonder if this was not the best way to go about this. Any help appreciated!</p>