title: How to clone or create a new copy of Map in java
body: <pre><code>Map&lt;String, WriteToFileColumnsModel&gt; temp = new ConcurrentHashMap&lt;&gt;(inputMap);
  temp.keySet().removeAll(targetMap.keySet());
  targetMap.putAll(temp);
  
  targetMap = new ConcurrentHashMap&lt;&gt;(inputMap);
  
  targetMap.putAll(inputMap);
  
  inputMap.forEach(targetMap::putIfAbsent);
  
  for (Map.Entry&lt;String, WriteToFileColumnsModel&gt; entry : inputMap.entrySet()) {
          targetMap.put(entry.getKey(), entry.getValue());
  }
  </code></pre>
  
  <p>I checked all the related questions on Stack Over Flow and tried the above possible ways. When I do any of the above way, new instance isn't created. When I alter targetMap, inputMap is altered too.</p>
  
  <p>Any help would be appreciated. Thanks in advance :)</p>