Friday, 9 December 2016

What is the difference between HashMap and Hashtable In Java ?


Here we will discuss all the differences between HashMap and HashTable In Java.


HashMap
HashTable
It is not synchronized.
It is synchronized.
It is not thread-safe.
It is thread-safe.
Its performance is fast because it is not thread-safe.
Its performance is slow because it is thread-safe.
It allows one null key and multiple null values.
It doesn’t allow null as a key or as a value.
It extends AbstractMap class.
It extends Dictionary class.
HashMap iterator is fail-fast.
HashTable iterator is fail-safe.
HashMap is not a legacy class, it was introduced in JDK 1.2.
HashTable is a legacy class.
HashMap is useful for single-threaded application.
HashTable is useful for multi-threaded application.
HashMap can be synchronized by using
HashMap<String, String> map = new HashMap<>();
Collections.synchronizedMap(map);
HashTable is internally synchronized and it cannot be unsynchronized.

Some similarities between HashMap and Hashtable are as follows :

HashMap
HashTable
HashMap does not maintain the insertion order of elements.
HashTable does not maintain the insertion order of elements.
HashMap implements the Map Interface.
HashtTable implements the Map Interface.
HashMap works on principles of Hashing.
HashTable works on principles of Hashing.


     
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



No comments:

Post a Comment