Ok, here is the bit I do not understand.
If you attempt to retrieve an object using the get() method and null is returned, it is still possible that null may be stored as the object associated with the key you supplied to the get() method. You can determine if this is the case by passing your key of the object to containsKey() method for map. This returns true if key is stored in the map
So, how is containsKey() supposed to tell me if the value associated with the key supplied is null?
This is the reference if you wanna check. Page 553
Ok, here is the bit I do not understand. If you attempt to retrieve
Share
Consider this simple snippet of code:
As you can see I put in the map two values, one of which is null. Thene i asked the map for three values: two of them are present (one is null), one is not. Look at the result:
The second and the third are the tricky part.
key2is present with null value so, usingget()you cannot discriminate whether the element is not in the map or is in the map with anullvalue. But, usingcontainsKey()you can, as it returns aboolean.