File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Hashtable vs HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hashtable vs HashMap" Watch "Hashtable vs HashMap" New topic

Hashtable vs HashMap

Ronnie Ho
Ranch Hand

Joined: Aug 10, 2005
Posts: 47

What is the major difference between a hashtable and hashmap? Thanks.
Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
Hashtable is synchronized, HashMap not.

Regards,<br />Seb<br /> <br />SCJP 1.4
Amar Shrivastava

Joined: Oct 17, 2005
Posts: 13
HashMap class is not thread-safe nad permits one null key,the HashTable class is thread-safe and permits non-null keys and values only.
The Thread-safety that <i>HashTable</i> class provides has a performance penalty. HashTable class is a legay class that has been retrofitted to implement the Map interface.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
if you are considering using HashTable or Collections.synchronizedMap(new HashMap())
because its methods are "thread-safe", check out java.util.concurrent.ConcurrentHashMap first:

Brian Goetz's articl on ConcurrentHashMap

ConcurrentHashMap API

There is no emoticon for what I am feeling!
Ronnie Ho
Ranch Hand

Joined: Aug 10, 2005
Posts: 47
Thanks all.
I agree. Here's the link:
subject: Hashtable vs HashMap
It's not a secret anymore!