Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Member-only story

How does HashMap handle a null key internally?

--

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…
Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

Thirupathi Pavan Sai
Thirupathi Pavan Sai

Written by Thirupathi Pavan Sai

Software Engineer | 1X Azure certified | Backend | Cyber Security Enthusiast | DevOps Enthusiast

No responses yet