Q- What is the difference between HashMap and HashTable in
java?
Both the HashMap and Hashtable implement the interface java.util.Map but
there are some differences which are mentioned below.
HashMap | Hashtable |
---|---|
HashMap is non-synchronized | Hashtable is synchronized |
HashMap is not thread-safe. Whereas Hashmap is not thread-safe and it cannot be shared between threads without synchronization. Map m = Collections.synchronizedMap(hashMap); |
Hashtable is thread-safe, and can be shared among multiple threads. As only one thread can access the Hashtable at a time |
HashMap permits one null key and multiple null values. | Hashtable will not allow null key or value. |
HashMap is faster. | Hashtable is slower than HashMap due to thread-safe. |
HashMap can be traversed by using the iterator. | Hashtable can be traversed by using enumerator and iterator. |
HashMap inherits AbstractMap class. | Hashtable inherits Dictionary class. |
Related Tutorials
- Java Collections Interview
- List Interface In Java
- ArrayList
- LinkedList
- Custom Own ArrayList Implementation
- Custom LinkedList implementation in java
- Set Interface In Java
- Map Interface In Java
- HashMap
- TreeMap
- HashMap Vs ConcurrentHashMap
- HashMap Vs HashTable In Java
- HashMap Vs HashSet In Java
- HashMap Vs TreeMap In Java
- HashMap vs LinkedHashMap In Java
- TreeSet Vs TreeMap In Java
- SortedSet Vs TreeSet In Java
- SortedMap Vs TreeMap In Java
- Array Vs ArrayList In Java
- ArrayList Vs LinkedList In Java
- How HashSet Works Internally
- How TreeMap Works Internally
- How HashMap Works Internally
- How ConcurrentHashMap Works Internally
- How To Detect Loop In A LinkedList In Java
- Detect And Remove Loop In A LinkedList
No comments:
Post a Comment