Thursday 21 July 2022

What is the difference between HashMap and Hashtable in JAVA ? : Mphasis JAVA Interview Question-2022

 

HashMap  vs.  Hashtable:

Both HashMap and Hashtable are two implementation class of Map interface which contains pair. In a pair, one is key and one is value.

There are many differences between HashMap and Hashtable.

                HashMap

 Introduced in 1.2 version

HashMap is not synchronized, that means it is not in thread safe.

HashMap allows one null key and multiple null values.

HashMap is faster.

We can traverse HashMap by Iterator.

                 Hashtable

Introduced in 1.0 version, that’s why it is called as legacy.

Hashtable is synchronized, that means it is thread safe.

Hashtable not allowed any null key or value.

Hashtable is slow.

We can traverse Hashtable by Enumerator and Iterator.



Our Services:
JAVA Training  ||  JAVA Projects  ||  JAVA Internship  || JAVA Placements || Python Training  || AI & Machine Learning with Python Training  || Data Science Training
Call to : 0674-2361252

1 comment: