participate


Java Programming [Archive] - HashTable or HashMap ? Which one is better ?
<<   Back to Forum  |   Give us Feedback
This topic has 2 replies on 1 page.
skeeter_xu
Posts:79
Registered: 3/24/03
HashTable or HashMap ? Which one is better ?   
Apr 28, 2003 9:41 PM

 
Hi guys,
It seems HashTable and HashMap implement the same functionality. Could someone tell me what is the difference between them and which one to choose under various conditions ?

Thank you very much.
Skeeter
 
trumpetinc
Posts:927
Registered: 12/17/99
Re: HashTable or HashMap ? Which one is better ?   
Apr 28, 2003 10:54 PM (reply 1 of 2)  (In reply to original post )

 
HashMap is the "prefered" class. HashTable is older...

That said, many developers still choose to use HashTable because it is synchronized by default. I personally prefer to take care of my own synchronization code, so this isn't a big deal for me...

You can also use a wrapper from the Collection class to turn a Map into a synchronized map...

If you can, use HashMap.

- K
 
monu_java
Posts:4
Registered: 4/25/03
Re: HashTable or HashMap ? Which one is better ?   
Apr 28, 2003 11:44 PM (reply 2 of 2)  (In reply to original post )

 
If you want your Map type collection to be thread safe, then you need to use Hashtable otherwise use HashMap. HashMap gives better performance than Hashtable because of it's non-synchronized methods.
 
This topic has 2 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums