HashMap or HashTable ?

Hello,

I'm about to develop something, which I originally planned to use a HashTable for, as I need something with it's functionality, and I haven't used HashMap's before.

My question is: In what cases would you choose a HashMap over a HashTable?

Regards;
LVL 25
InteractiveMindAsked:
Who is Participating?
 
CEHJCommented:
HashMap is generally to be preferred at all times, but it's not thread-safe. You can make it thread safe through the collections API if necessary though
0
 
CEHJCommented:
>> ... at all times  ...

(Apart from when legacy code support is needed)
0
 
InteractiveMindAuthor Commented:
Hey CEHJ,

I'm not sure what you mean by "Thread Safe". Could you please elaborate?

Cheers.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
CEHJCommented:
You need to ensure that the Map's behaviour is predictable when accessed by multiple threads:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#synchronizedMap(java.util.Map)
0
 
InteractiveMindAuthor Commented:
Ah, I get it.  :-)

Thanks, once again, CEHJ.
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.