I have this object:
Map<Long, Set<String>> resourcesByID = new HashMap<Long, Set<String>>();
and another:
Set<String> resources;
When I want to put more Set into the HashMap it will override the elements of the Set, that I put into previously. Why? And how can I resolve this problem?
resourcesById. It is likely you are just putting a new Set into the HashMap. What you should do is check if the HashMap contains the Long you are about to use to insert. If it does, you must get the Set from the map and add all elements from the insertion Set into it. If it does not, just insert your insertion set.Setfor each new key, and instead you are constantly pushing new elements into the sameresourcesobject then putting multiple references to saidresourcesobject for various keys into the hashmap.