title: How to update a value in a map if it exists else insert it
body: <p>I did a search and was amazed this hadn't been asked before (at least I couldn't find it).</p>
  
  <p>I have a map like this:</p>
  
  <pre><code>Map&lt;String, String&gt; myMap
  </code></pre>
  
  <p>I know that I can check if a key exists within the map using<code>containsKey(Object key);</code> and I can replace a value using <code>replace(String key, String value);</code> and naturally put a value using <code>put(String key, String value);</code></p>
  
  <p>Now if I want to check a value if it exists update it, else insert it, I have to use a condition:</p>
  
  <pre><code>if(myMap.containsKey(key)) {
      myMap.replace(key, value);
  } else {
      myMap.put(key, value);
  }
  </code></pre>
  
  <p>Is there a  better way of doing this? I personally feel the condition is a bit unnecessary and overcomplicating something which could be one line rather than five!</p>