title: How to create a map of maps from a list of maps with Java 8 streaming api
body: <h2>Background</h2>
  
  <p>I have a list of maps that looks something like this:</p>
  
  <pre><code>[
    {
      "name": "A",
      "old": 0.25,
      "new": 0.3
    },
    {
      "name": "B",
      "old": 0.3,
      "new": 0.35
    },
    {
      "name": "A",
      "old": 0.75,
      "new": 0.7
    },
    {
      "name": "B",
      "old": 0.7,
      "new": 0.60
    }
  ]
  </code></pre>
  
  <p>and I want the output to look like this:</p>
  
  <pre><code>{
    "A": {
      "old": 1,
      "new": 1
    },
    "B": {
      "old": 1,
      "new": 0.95
    }
  }
  </code></pre>
  
  <p>...where the values of <code>old</code> and <code>new</code> are summed for each related entry.</p>
  
  <p>The data type of the list of maps is <code>List&lt;Map&lt;String, Object&gt;&gt;</code>, so the output should be a <code>Map&lt;String, Map&lt;String, Double&gt;&gt;</code>.</p>
  
  <h2>What I've Tried</h2>
  
  <p>With some diagram drawing, documentation reading, and trial and error, I was able to come up with this:</p>
  
  <pre><code>data.stream()
      .collect(
          Collectors.groupingBy(entry -&gt; entry.get("name"),
              Collectors.summingDouble(entry -&gt;
                  Double.parseDouble(entry.get("old").toString())))
      );
  </code></pre>
  
  <p>to produce an object of type <code>Map&lt;String, Double&gt;</code>, where the output is</p>
  
  <pre><code>{
    "A": 1,
    "B": 1
  }
  </code></pre>
  
  <p>for the summations of the <code>old</code> values. However, I can't quite transform it into a map of maps. Something like this:</p>
  
  <pre><code>data.stream()
      .collect(
          Collectors.groupingBy(entry -&gt; entry.get("name"),
              Collectors.mapping(
                  Collectors.groupingBy(entry -&gt; entry.get("old"),
                      Collectors.summingDouble(entry -&gt;
                          Double.parseDouble(entry.get("old").toString())
                      )
                  ),
                  Collectors.groupingBy(entry -&gt; entry.get("new"),
                      Collectors.summingDouble(entry -&gt;
                          Double.parseDouble(entry.get("new").toString())
                      )
                  )
              )
          )
      );
  </code></pre>
  
  <p>doesn't work, because <code>Collectors.mapping()</code> only takes one mapping function and a downstream collector, but I'm not sure how to map two values at once.</p>
  
  <p>Is there another function I need to create mappings of two different values? Any suggestions on better ways of doing this is greatly appreciated as well.</p>