C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers

114 comments

10,705 users

Differences between HashMap and Hashtable?

0 votes
22 views
asked Jan 23, 2014 by john Guru (27,140 points)

1 Answer

0 votes
There are several differences between HashMap and Hashtable in Java:
 
Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.
Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
One of HashMap's subclasses is LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.
Since synchronization is not an issue for you, I'd recommend HashMap. If synchronization becomes an issue, you may also look at ConcurrentHashMap.
 
answered Jan 23, 2014 by sara Guru (24,570 points)

Related questions

0 votes
1 answer 13 views
13 views asked Jan 10, 2014 by smith Geek (15,340 points)
0 votes
1 answer 13 views
13 views asked Dec 29, 2013 by john Guru (27,140 points)
0 votes
3 answers 23 views
23 views asked Dec 22, 2013 by rajesh Guru (39,140 points)
0 votes
1 answer 27 views
0 votes
1 answer 12 views
...