Bear Bibeault wrote:Look at line 41. What happens if the the get() specifies a key that does not exist?
Dave Tolls wrote:For the first issue it sounds like you should be overwriting the whole entry? In this case the entry is the Set<String>, not a single String in the Set.
Were you given the class to work with, or is this something you put together?
ETA: It's not that clear to me, so take what I say with a large pinch of salt and get clarification from whoever set the requirements.
Rickey Fuller wrote:"You don't have to create a new list. The method should be taking as an argument your key along with your value.
method(KeyType aKey, ValueType aValue)
// you then add aKey and aValue to the map
you then create an instance of your class, a key and value then use these as an argument for the method"
Not sure if that is any help, but it has just made me more confused. I think I am gonna take a break from and come back later
Dave Tolls wrote:Well, that shows your method has an incorrect signature.
And now it makes sense.
Your value type is a Set<String>, not a String.
You would then do a put().
Dave Tolls wrote:Except that doesn't fulfil the requirements.
Create a method called addMapEntry() which takes 2 arguments representing a key and a value. It adds the key and value to the map and if the key is already present the existing value is overwritten. Returns no value.
String is not the value. Set<String> is, at least for the example the OP has chosen to write.
The idea seems to be that the method replaces the entry in the map or creates a new one. All a bit pointless as put() already does that, but then there could be an aspect to this we don't know about.
Rickey Fuller wrote:Create a method called addMapEntry() which takes 2 arguments representing a key and a value....