Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronized HashMap Vs Hashtable

 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one is beeter Synchronized HashMap / Hashtable ? because Hashtable is defaultly Synchronized?
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashMap implementation is not synchronized. Hashtable is. It really depends on the situation that you've to decide which is a better choice. But, being synchronized has a little trade-off in performance.

You could instead synchronize the method or code block that accesses the HashMap object instead.

HTH.
 
Jayaraj Sekaran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can actually go for HashMap itself.

The advantages of HaspMap are:
1) Not synchronized
2) Can have 'Null' as value
3) Can have 'Null' as a key also.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic