I'm using a HashMap that I duplicate, but when I change values from the second HashMap, the first HahsMap get its values also change.
There is my code :
HashMap<String, processing.core.PImage> firstMap = new HashMap<>();
// Filling the first HashMap with values.
System.out.println(firstMap.get("test").height); // returning 16
// Then, I duplicate the HashMap :
HashMap<String, processing.core.PImage> secondMap = new HashMap<>(firstMap);
secondMap.forEach((name, image) -> {
image.resize(1, 1);
// This sets height and width of images as 1
// BUT, logically, it must change only values from SECONDMap, not FIRSTMap
});
System.out.println(firstMap.get("test").height); // returning 1
// It returns 1 but I didn't change the values from the FIRST map ??
So I just don't understand what is happening and how to fix it ?