Saturday, April 7, 2012

HashMap Vs HashTable

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 difference between the two is that access to the Hashtable is synchronized (by default) while access to the HashMap isn't.

Another difference is that iterator in the HashMap is fail-safe while the iterator for the Hashtable isn't. If you change the map while iterating, you'll know.

And, a third difference is that HashMap permits null values in it, while Hashtable doesn't.

No comments:

Post a Comment