it SCJP book by K Siera & Berts Bates it is written that "hash map can have one null key & multiple null values" null values is alright but how can it has null key. then can values be retrieved from it.
sweety sinha wrote: "hash map can have one null key & multiple null values" null values is alright but how can it has null key. then can values be retrieved from it.
Had you tried to put a "null" value as a key in HashMap instance, lets try it and tell us whether you're able to fetch the respective "value" from it ?
HashMap object hold key and it's corresponding value.
See the following non-generic code example
Ouput is English not Maths.
The second put method call changes value to English. Initially null key point to Maths but now point to English.
In such a way HashMap have unique keys and multiple values. Multiple values may be same or different but keys must have unique values.