I have a Map object where I use integers as the keys, and Lists as the corresponding values. Here is my code.
Map<Integer, List<Double>> dataDouble = new HashMap<Integer, List<Double>>();
List<Double> dubList = new ArrayList<Double>();
for(double i = 0; i < 10; i++)
dubList.add(i);
dataDouble.put(1, dubList);
//dubList.clear();
for(int i = 10; i < 16; i++)
dubList.add(i);
dataDouble.put(2, dubList);
Set<Integer> keyset = dataDouble.keySet();
for(Integer key : keyset) {
System.out.println("ttKEY: " + key);
List<Double> finList = dataDouble.get(key);
for(double value : finList)
System.out.println("VALUE: " + value);
}
}
If I do not include the clear statement then the second list is not updated, and I get 2 block of 1 to 10 in the print statements. If I do add the clear command, only 10-15 is printed in the two blocks.
My question is, why does the clear command clear data already added to the Map, and also why does adding new data to the list and putting it on the Map not actually change the values?
