I have a map (Map<String, Set<String>>
), and want to copy the map to a new map object. However, if I just feed the map to the say HashMap
constructor (new HashMap<String, Set<String>>(oldMap)
) it won't do a full copy, and only copies the reference to the set, which can be modified and those changes will be reflected in the new map.
Is there a more simply way of doing a full copy other than iterating over each key/value pair and creating a new HashSet
for each set then adding that to the map?