Frage im Vorstellungsgespräch bei EPAM Systems

What if we insert with key null to a HashMap?

Antworten zu Vorstellungsgespräch

Anonym

4. Mai 2019

Didn't know, however, it's a very edge case, you can insert and the hashcode will be 0, so it's identifying the '0' bucket.

Anonym

1. Sept. 2020

HashMap allows null as both key and value, as well. So you can associate a value to null key. However, TreeMap throws a NullPointerException if you try to put a key with null value.