What is the best of cloning a LinkedHasMap
in Java?
I already tried:
Map<String, Object> clonedMap = new LinkedHashMap<String, Object>(originalMap);
But that didn't work.
What is the best of cloning a LinkedHasMap
in Java?
I already tried:
Map<String, Object> clonedMap = new LinkedHashMap<String, Object>(originalMap);
But that didn't work.
The easiest way to get a deep copy is to serialize the map and then deserialize it. The faster way is to go thought the whole map, clone each key/value and put it to a new map.
In case you need a shallow copy - your snippet does that correctly.