Problem
If I explicitly loop through every element in hash map A and "put" each element in hash map B then I have no problem. But if try calling A.putAll(B)
for some reason B ends up null.
The code that is working is the basic iterator approach show below:
Iterator it = A.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry = (Map.Entry) it.next();
B.put((Integer)entry.getKey(),(Integer)entry.getKey());
}
Where I run into trouble is when I do this.
HashMap A = loadHashMapWithData();
HashMap B = new HashMap();
A.putAll(B);
System.out.println(A);
System.out.println(B);
The second hashmap I am trying to pass data into always ends up "null". Going forward I am using the 1st approach but it would be nice to know why putAll is failing.