I have two HashMaps defined as follows:
HashMap EventTable = new HashMap();
HashMap MainTable = new HashMap ();
Now, suppose I insert some data into EventTable:
EventTable.put("name", "Test Event Name");
Then, suppose we insert the EventTable into the MainTable:
MainTable.put("table", EventTable);
and then print out MainTable:
{table={name=Test Event Name}}
Now if I modify Event Table as follows:
EventTable.put("more names", "More test events");
This changes the MainTable as well:
{table={more names=More test events, name=Test Event Name}}
So obviously, EventTable is being passed by reference to MainTable.
I don't understand why EventTable is being passed by reference.
Ideally I would like to reuse the EventTable HashMap to create other entries, while retaining my old entries, so I would like to pass EventTable by value.
EDIT:
Forgot to mention this in the main question, but when I add a String to the MainTable, that does not change when I modify the string afterwards. So how is the behavior is different for the String?