You are the victim of the difference between shallow copy and deep copy.
Shallow copies duplicate as little as possible. A shallow copy of a collection is a copy of the collection structure, not the elements. With a shallow copy, two collections now share the individual elements.
Deep copies duplicate everything. A deep copy of a collection is two collections with all of the elements in the original collection duplicated.
The line "map2.putAll(map1);" essentially creates a shallow copy and both map1 and map2 share the reference to the same data. If you want them to be completely different, it is recommended that you duplicate everything. One possible way to do that is to use the MapEntry and copy each record manually.
HashMap<String, ArrayList<String>> map1 = new HashMap<String, ArrayList<String>>();
HashMap<String, ArrayList<String>> map2 = new HashMap<String, ArrayList<String>>();
ArrayList<String> t1 = new ArrayList<String>();
t1.add("a");
t1.add("a");
t1.add("a");
t1.add("a");
t1.add("a");
map1.put("1", t1);
for (Map.Entry<String, ArrayList<String>> entry : map1.entrySet()) {
map2.put(entry.getKey(), new ArrayList<String>());
for(String s: entry.getValue()) {
map2.get(entry.getKey()).add(s);
}
}
System.out.println("Map1: " + map1.toString());
System.out.println("Map2: " + map1.toString());
map2.get("1").set(0, "b");
System.out.println("Map1: " + map1.toString() + " | " + "Map2: " + map2.toString());