I need to make a copy of HashMap<Integer, List<MySpecialClass> >
but when I change something in the copy I want the original to stay the same. i.e when I remove something from the List<MySpecialClass>
from the copy it stays in the List<MySpecialClass>
in the original.
If I understand it correctly, these two methods create just shallow copy which is not what I want:
mapCopy = new HashMap<>(originalMap);
mapCopy = (HashMap) originalMap.clone();
Am I right?
Is there a better way to do it than just iterate through all the keys and all the list items and copy it manually?