Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is Hashtable different to Hashmap [duplicate]

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?

like image 610
user1813746 Avatar asked Nov 10 '12 00:11

user1813746


1 Answers

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.

like image 149
PermGenError Avatar answered Oct 12 '22 20:10

PermGenError