Both HashMap and Hashtable classes are Map interface implementations . HashMap and Hashtable classes have below defferences based on their functionality and behavior.
This blog explains the installation and usage of the Java programming language. It also contains examples for standard programming tasks.This is used to enhance the java programming skills.
HashMap | Hashtable |
HashMap is not a legacy class | Hashtable is a legacy class |
HashMap is not synchronized. If required HashMap can be synchronized as below: Map m = Collections.synchronizeMap(hashMap); | Hashtable is internally synchronized and can't be unsynchronized. It is thread-safe and can be shared with many threads. |
HashMap can contain one null key and multiple null values. | Hashtable cannot contain any null key or null value. |
HashMap is not thread-safe, so it is useful for non-threaded applications. | Hashtable is thread-safe, and it can be shared between various threads. |
HashMap inherits the AbstractMap class | Hashtable inherits the Dictionary class. |
Iterator in the HashMap is fail-safe | Enumerator for the Hashtable is not and throw ConcurrentModificationException |
HashMap is fast | Hashtable is slow |
HashMap inherits AbstractMap class. | Hashtable inherits Dictionary class. |
HashMap is traversed by Iterator. | Hashtable is traversed by Enumerator and Iterator. |
No comments:
Post a Comment
Hello Buddy, if you have any doubts or need any clarification , feel free to comment. Thanks.