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

Synchronized HashMap Vs Hashtable

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1404
Which one is beeter Synchronized HashMap / Hashtable ? because Hashtable is defaultly Synchronized?
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
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.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Jayaraj Sekaran

Joined: Apr 17, 2005
Posts: 5
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.

SCJP 1.4<br />SCWCD 1.4<br />WSAD 5.0
I agree. Here's the link:
subject: Synchronized HashMap Vs Hashtable
jQuery in Action, 3rd edition