Member-only story
How does HashMap handle a null key internally?
3 min readApr 8, 2025
100 Days — 100+ Interview Questions
Hey friend,
From today, we will learn 100+ Interview Questions in 100 Days with complete, detailed explanations from scratch, which will help us understand concepts better and help us crack interviews.
You can get the complete Interview Series here.
Question
Can we use null as a key in a HashMap? What about Hashtable?
Before diving into the question, let’s start from basics like what is Map, HashTable and the discuss their features.
What is a Map in Java?
- In Java, a Map is an object that stores key-value pairs. Each key is unique, and each key maps to exactly one value.
- There are multiple implementations of Map Interface in Java such as HashMap, LinkedHashMap, TreeMap, HashTable, ConcurrentHashMap etc.
- Each implementation has it’s own features and structure.
What is a HashMap?
- HashMap is one of the implementations of Map Interface in Java
- HashMap is part of java.util package.
- It stores data in key-value pairs and uses a hashing technique to quickly…