Possible Duplicate:
Differences between HashMap and Hashtable?
I've seen hash tables and hash maps used in different code but they look like they do the same thing. Is there a difference between them? Which one should I use in my code?
Possible Duplicate:
Differences between HashMap and Hashtable?
I've seen hash tables and hash maps used in different code but they look like they do the same thing. Is there a difference between them? Which one should I use in my code?
java.util.Hashtable methods are synchronized , java.util.Hashmap methods are not. If you use Hashtable there will be a performance hit as no two threads will be able to access its methods at the same time. If you care about Thread safety in your app Hashtable is the way to go. if you dont care about thread safety Hashmap is the way to go as it is mor eefficient then hashtable. also java.util.Hashtable doesnt allow any null keys, where as java.util.HashMap allows one null key.
Hashtable is synchronized, where as HashMap is not. This means if you only have a single thread accessing the data, use a HashMap, otherwise use a Hashtable.
HashTable dont't allow null keys where as hashmap allows one null key