Map<String, WriteToFileColumnsModel> temp = new ConcurrentHashMap<>(inputMap);
temp.keySet().removeAll(targetMap.keySet());
targetMap.putAll(temp);
targetMap = new ConcurrentHashMap<>(inputMap);
targetMap.putAll(inputMap);
inputMap.forEach(targetMap::putIfAbsent);
for (Map.Entry<String, WriteToFileColumnsModel> entry : inputMap.entrySet()) {
targetMap.put(entry.getKey(), entry.getValue());
}
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.
Any help would be appreciated. Thanks in advance :)