You are here:
» HashMap Vs Hashtable
HashMap vs Hashtable
This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.
what is the difference between HashMap vs Hashtable Which is best to Use

1 year 43 weeks ago
Tags:
Hi,
They are almost the same thing. The big differences are that HashMap is the implementation of a Hashtable on a Map interface, is not synchronized, and it allows null values for key and value, while Hashtable doesn't.
Alessandro A. Garbagnati
Both provide key-value access to data. The Hashtable is one of the original collection classes in Java. HashMap is part of the new Collections Framework, added with Java 2, v1.2.
The key differnce between the two is that access to the Hashtable is synchronized on the table while access to the HashMap isn't. You can add it, but it isn't there by default.
Another difference is that iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't. If you change the map while iterating, you'll know.
-John Zukowsk
1. The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesn't allow nulls).
2. HashMap does not guarantee that the order of the map will remain constant over time.
3. HashMap is non synchronized whereas Hashtable is synchronized.
4. Iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't
to read more about Hashtable vs HashMap See here.
Post Comment