Difference between HashMap and Hashtable

HashMap Hashtable
HashMap is non synchronized. It is not-thread safe and can't be shared between many threads without proper synchronization code. Hashtable is synchronized. It is thread-safe and can be shared with many threads.
HashMap allows one null key and multiple null values. Hashtable doesn't allow any null key or value.
) HashMap is a new class introduced in JDK 1.2. Hashtable is a legacy class.
HashMap is fast. Hashtable is slow.
We can make the HashMap as synchronized by calling this code Map m = Collections.synchronizedMap(hashMap);
Hashtable is internally synchronized and can't be unsynchronized.
HashMap is traversed by Iterator. Hashtable is traversed by Enumerator and Iterator.


Copyright ©2017 Design& development by HN