title: Java 8 lambdas grouping by multiple fields
body: <p>I have a list of pojos that I want to perform some grouping on. Something like:</p>
  
  <pre><code>public class Pojo {
      private final Category category;
      private final BigDecimal someValue;
  }
  
  public class Category {
      private final String majorCategory;
      private final String minorCategory;
  }
  </code></pre>
  
  <p>I want a <code>Map&lt;String, Map&lt;String, List&lt;Pojo&gt;&gt;&gt;</code> where the key is <code>majorCategory</code> and the value is a <code>Map</code> with key <code>minorCategory</code> and values is a <code>List</code> of <code>Pojo</code> objects for said <code>minorCategory</code>.</p>
  
  <p>I intend to use Java 8 lambdas to achieve this. I can get the first level of grouping done with the following:</p>
  
  <pre><code>Map&lt;String, Pojo&gt; result = list
      .stream()
      .collect(groupingBy(p -&gt; p.getCategory().getMajorCategory()));
  </code></pre>
  
  <p>How can I now group again on <code>minorCategory</code> and get the <code>Map&lt;String, Map&lt;String, List&lt;Pojo&gt;&gt;&gt;</code> I desire?</p>
  
  <p><strong>Update</strong></p>
  
  <p>The first answer provided is correct for the example provided initially, however I have since updated the question. Ruben's comment in the accepted answer, provides the final piece of the puzzle.</p>