Putting a new value into a Map if not present, or adding it if it is : <p>I have a <code>java.util.Map&lt;Foo, Double&gt;</code> for a key-type class <code>Foo</code>. Let's call the instance of the map <code>map</code>.</p>

<p>I want to add {<code>foo</code>, <code>f</code>} (<code>foo</code> is an instance of <code>Foo</code>, and <code>f</code> a <code>Double</code>) to that map. But if the key <code>foo</code> is already present I want to sum <code>f</code> to the current value in that map.</p>

<p>Currently I use</p>

<pre><code>Double current = map.get(foo);
f += current == null ? 0.0 : current;
map.put(foo, f);
</code></pre>

<p>But is there a funky way of doing this in Java 8, such as using <code>Map#merge</code>, and <code>Double::sum</code>?</p>

<p>Regrettably I can't figure it out.</p>

<p>Thank you.</p>
