• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hashtable vs HashMap  RSS feed

 
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.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashtable is synchronized, HashMap not.
 
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.
 
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
Boost this thread!