Changing the Value of a map
Map<Integer, Set<String>> a Map = etc....;
Having declared the map above correctly, if I wish to add a member to the existing Set of strings at a particular key is it sufficient to use:
Set<String> aSet;
aSet = aMap.get(Integer anInt);
aSet.add(aString);
Is the value of the key/value pairing now modified in aMap?
Re: Changing the Value of a map
Quote:
Originally Posted by
Whisperer
Is the value of the key/value pairing now modified in aMap?
Yup, it is modified in aMap and as a value in the set aSet as well; Java doesn't make any copies of an object when it stores (or retrieves it) in a Collection.
kind regards,
Jos
Re: Changing the Value of a map
Thanks Jos, just to finish it off, I assume that closing aSet does not affect the updated aMap.
TIA GT
Re: Changing the Value of a map
Quote:
Originally Posted by
Whisperer
Thanks Jos, just to finish it off, I assume that closing aSet does not affect the updated aMap.
TIA GT
How do you 'close' a Set? If you 'forget' about a Set while there still exists a reference to it (possibly in another Collection), nothing happens to te Set.
kind regards,
Jos
Re: Changing the Value of a map
Quote:
Originally Posted by
Whisperer
Thanks Jos, just to finish it off, I assume that closing aSet does not affect the updated aMap.
TIA GT
How do you 'close' a Set? If you 'forget' about a Set while there still exists a reference to it (possibly in another Collection), nothing happens to te Set.
kind regards,
Jos