I am trying to create a HashMap which string keys and HashSet of Strings as values. I wrote the following code for this.
The file cvtfile.txt has the following content:
The Output is:
I am not able to make out why is the value set that is read at last is getting mapped to all the keys.
I would be grateful for any comments/suggestions.
So that means the put method of the HashMap class does not copy the object to the map. It just links the object to the map value, so that the last value added the object persists.
SillyCon!
Ireneusz Kordal
Ranch Hand
Posts: 423
posted 11 years ago
So that means the put method of the HashMap class does not copy the object to the map.
Yes, it does not copy the object (the content of the object), it only stores the reference to the object.
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop