title: Java Stream: Grouping and counting by multiple fields
body: <p>I have the following object:</p>
  
  <pre><code>class Event {
  private LocalDateTime when;
  private String what;
  
  public Event(LocalDateTime when, String what) {
    super();
    this.when = when;
    this.what = what;
  }
  
  public LocalDateTime getWhen() {
    return when;
  }
  
  public void setWhen(LocalDateTime when) {
    this.when = when;
  }
  
  public String getWhat() {
    return what;
  }
  
  public void setWhat(String what) {
    this.what = what;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I need to aggregate by year/month (yyyy-mm) and event type, and then count. For example the following list</p>
  
  <pre><code>List&lt;Event&gt; events = Arrays.asList(
    new Event(LocalDateTime.parse("2017-03-03T09:01:16.111"), "EVENT1"),
    new Event(LocalDateTime.parse("2017-03-03T09:02:11.222"), "EVENT1"),
    new Event(LocalDateTime.parse("2017-04-03T09:04:11.333"), "EVENT1"), 
    new Event(LocalDateTime.parse("2017-04-03T09:04:11.333"), "EVENT2"),
    new Event(LocalDateTime.parse("2017-04-03T09:06:16.444"), "EVENT2"),
    new Event(LocalDateTime.parse("2017-05-03T09:01:26.555"), "EVENT3")
  );
  </code></pre>
  
  <p>should produce the following result:</p>
  
  <pre><code>Year/Month  Type  Count
  2017-03     EVENT1    2  
  2017-04     EVENT1    1
  2017-04     EVENT2    2
  2017-04     EVENT3    1
  </code></pre>
  
  <p>Any idea if (and if so, how) I can achieve that with Streams API? </p>