title: Java group by then collect to list of custom objects
body: <p>I have a stream of <code>Element</code> from csv file</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Element {
      private String site;
      private String value;
      private Date date;
  ...
  }
  </code></pre>
  
  <p>and I want to group elements by <code>site</code> to a list of <code>Stat</code> objects</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Stat {
      private List&lt;Info&gt; infos;
      private String site;
  
      public Stat (String site, List&lt;Info&gt; infos) {
  ...
      }
  }
  
  public class Info {
      private String value;
      private Date date;
  ...
  }
  </code></pre>
  
  <p>Here's where I am </p>
  
  <pre><code>Map&lt;String, List&lt;Element&gt;&gt; elementsBySite = elements.stream().collect(Collectors.groupingBy(Element::getSite));
  </code></pre>
  
  <p>is it possible to re-map my list of <code>Element</code> to a list of stat in a single ?</p>
  
  <p>something like </p>
  
  <pre><code>Map&lt;String, List&lt;Stats&gt;&gt; statsBySite = elements
      .stream()
      .collect(Collectors.groupingBy(Element::getSite, 
          Collectors.collectingAndThen(Collectors.toList(), 
               // transform each element to Info
               // then create a Stats object with all infos for a given site
  ));
  </code></pre>