Before this, I would suggest to go through the topic Iterator V/S Enumeration here. There are some significant factors that makes both of these data structures different
- This is the most important difference between the two.
- Hash tables are synchronized and thread safe whereas Hash maps are not.
- HashMap allows one null key and multiple null values, whereas hash table doesn't allow neither null values not null keys.
- Values in hash map are iterated using an iterator, whereas in hash table values are iterated using enumerator.
- Only Vector other then hash table uses enumerator to iterate through elements.
- Iterator in hash map is fail fast iterator, whereas enumerator for hash table is not.
- If hash table is structurally modified at any time after the iterator is created other then iterators own remove method, it will throw Concurrent Modification exception.
- Structural modification means adding or removing elements from the collection.
- HashTable is a subclass of Dictionary, which is now obsolete from JDK 1.7
- HashMap is much faster and uses less memory because it is not synchronized.
- Order of elements cannot be guaranteed, because both of these work based on the hashing logic. use Linked Hash map for that
- Both of them comes from Map interface.
- Both provides constant time for performance for put and get methods, assuming that objects are distributed uniformly.
- Both works on the principle of hashing
Avoid using HashTable, as they are obsolete now, ConcurrentHashMap has replaced it.
Single threaded apps - use HashMap