---
title: "What are the differences between HashMap and HashTable in Java?"  
description: "What are the differences between HashMap and HashTable in Java?"  
author: "Mukul Goenka"  
published: 2021-11-21  
updated: 2023-06-16  
canonical: https://www.mindstick.com/interview/33840/what-are-the-differences-between-hashmap-and-hashtable-in-java  
category: "java"  
tags: ["java", "hashtable"]  
reading_time: 3 minutes  

---

# What are the differences between HashMap and HashTable in Java?

\

| **HashMap** | **HashTable** |
| --- | --- |
| HashMap is not synchronized thereby making it better for non-threaded applications. | HashTable is synchronized and hence it is suitable for threaded applications. |
| Allows only one null key but any number of null in the values. | This does not allow null in both keys or values. |
| Supports order of insertion by making use of its subclass LinkedHashMap. | Order of insertion is not guaranteed in HashTable. |

\

## Answers

### Answer by Aryan Kumar

The HashMap and HashTable classes in Java are both implementations of the Map interface. They both use a hash table to store key-value pairs. However, there are some key differences between the two classes.

- **Synchronization:** HashMap is not synchronized, while HashTable is synchronized. This means that HashMap can be accessed by multiple threads without synchronization, while HashTable must be synchronized to prevent race conditions.
- **Null keys and values:** HashMap allows one null key and multiple null values, while HashTable does not allow any null keys or values.
- **Performance:** HashMap is generally faster than HashTable, especially when it is not being accessed by multiple threads.

In general, HashMap is a good choice for applications that do not need to be thread-safe and that require high performance. HashTable is a good choice for applications that need to be thread-safe and that do not require high performance.

Here is a table that summarizes the key differences between HashMap and HashTable:

| Feature | HashMap | HashTable |
| --- | --- | --- |
| Synchronization | Not synchronized | Synchronized |
| Null keys and values | Allows one null key and multiple null values | Does not allow any null keys or values |
| Performance | Generally faster | Slower |
| Use cases | Applications that do not need to be thread-safe and that require high performance | Applications that need to be thread-safe and that do not require high performance |

### Answer by Mukul Goenka

\

| **HashMap** | **HashTable** |
| --- | --- |
| HashMap is not synchronized thereby making it better for non-threaded applications. | HashTable is synchronized and hence it is suitable for threaded applications. |
| Allows only one null key but any number of null in the values. | This does not allow null in both keys or values. |
| Supports order of insertion by making use of its subclass LinkedHashMap. | Order of insertion is not guaranteed in HashTable. |

\


---

Original Source: https://www.mindstick.com/interview/33840/what-are-the-differences-between-hashmap-and-hashtable-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
