Hashtable Vs HashMap in Java
- A Hashtable is an array of list, where each list is called as bucket.
- The position of bucket is identified by calling the hashcode () method.
- A Hashtable contains values based on the key.
1. Hash table contains only unique elements.
2. It may not have any null key or value.
- The HashMap & HashTable both are similar
- HashMap contains values based on the key.
- HashMap implements on Map interface & extends AbstractMap class.
1. It contains only unique elements.
2. It may have one null key and multiple null values.
3. It maintains no order.
Similarities between Hashtable and HashMap in Java
- Both Hashtable and HashMap implements java.util.Map interface library.
- Hashtable and HashMap both are hash based collection and works on the principle of hashing.
- Both Hashtable and HashMap provides constant time performance for put and get method and the objects are distributed uniformly across the bucket. From JDK 4 both Hashtable and HashMap are part of Java collection framework.
Difference between Hashtable and HashMap in Java
- HashMap is not thread-safe while Hashtable is a thread-safe collection.
- HashMap will not synchronized but it performs better than Hashtable.
- The third difference on Hashtable vs HashMap is that Hashtable is obsolete class and we should be using ConcurrentHashMap in the place of Hashtable in Java.
- Difference between Hashtable and HashMap in Java
- Difference between HashMap and Hashtable
- What is difference between HashMap and Hashtable in Java?
- java - Differences between HashMap and Hashtable?
- What are the differences between HashMap and Hashtable?
- What is the difference between Hashtable and HashMap?
- diff b/w hashmap and hashtable
- difference b/w hashmap and hashtable
- differences b/w hashtable vs hashmap
- why hashmap is faster than hash table
- advantage of hashmap over hashtable