Saved Bookmarks
| 1. |
Can You Store A Null Key In Java Hashmap? |
|
Answer» YES, HashMap allows ONE null key which is stored at the FIRST location of bucket array e.g. bucket[0] = value. The HashMap doesn't call hashCode() on null key because it will throw NullPointerException, HENCE when a user call get() method with null then the value of the first index is returned. Yes, HashMap allows one null key which is stored at the first location of bucket array e.g. bucket[0] = value. The HashMap doesn't call hashCode() on null key because it will throw NullPointerException, hence when a user call get() method with null then the value of the first index is returned. |
|