title: Mutable version of Map.merge
body: <p>Java 8 has introduced some nice methods to the <code>Map</code> interface. To me, a gap is that there is no mutable version of the <code>merge</code> method.</p>
  
  <p>For example, suppose <code>map</code> is a <code>Map&lt;String, List&lt;Integer&gt;&gt;</code> and you want to do this:</p>
  
  <pre><code>List&lt;Integer&gt; list = map.get("a");
  if (list == null)
      list = map.put("a", new ArrayList&lt;&gt;());
  list.add(1);
  </code></pre>
  
  <p>(I am aware that you can use Guava's <code>MultiMap</code> for this kind of thing, but I am interested in standard Java.) </p>
  
  <p>To me, it feels like there ought to be a nice way of simplifying this in Java 8, but I can't find it. I reckon it should be a single method call, like</p>
  
  <pre><code>map.mutableMerge("a", 1, ArrayList::new, List::add);     // Not real code
  </code></pre>
  
  <p>but the best I could come up with using the new methods is</p>
  
  <pre><code>map.computeIfAbsent("a", k -&gt; new ArrayList&lt;&gt;());
  map.compute("a", (k, v) -&gt; {
      v.add(1);
      return v;
  });
  </code></pre>
  
  <p>but this is no better than the original. Am I missing something obvious?</p>