Wednesday 30 December 2015

hash map and hash table difference

Difference between HashMap and HashTable / HashMap vs HashTable 

1. Synchronization or Thread Safe :  This is the most important difference between two . HashMap is non synchronized and not thread safe.On the other hand, HashTable is thread safe and synchronized.
When to use HashMap ?  answer is if your application do not require any multi-threading task, in other words hashmap is better for non-threading applications. HashTable should be used in multithreading applications.

2. Null keys and null values :  Hashmap allows one null key and any number of null values, while Hashtable do not allow null keys and null values in the HashTable object.



3. Iterating the values:  Hashmap object values are iterated by using iterator .HashTable is the only class other than vector which uses enumerator to iterate the values of HashTable object.



HashMapHashtable



SynchronizedNoYes



Thread-SafeNoYes



Null Keys and Null valuesOne null key ,Any null valuesNot permit null keys and values



Iterator typeFail fast iteratorFail safe iterator



PerformanceFastSlow in comparison



Superclass and LegacyAbstractMap , NoDictionary , Yes

No comments:

Post a Comment