intermediateCollections233 of 436

Why does HashMap allow one null key?

Tests whether you know HashMap special-cases the null key by always placing it in bucket 0 (since hashCode() can't be called on null), and that only one null key can exist because a Map's keys must be unique -- a deliberate design choice, not an accident of the hashing algorithm.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

← Back to all Core Java questions