Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hashtable vs HashMap

 
Ronnie Ho
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What is the major difference between a hashtable and hashmap? Thanks.
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashtable is synchronized, HashMap not.
 
Amar Shrivastava
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ronnie Ho
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic