search
Login

Categories


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

3.8k questions

4k answers

117 comments

10.7k users

0 votes
23 views
asked Guru 27.1k points 31 47 92

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 Guru 24.6k points 29 51 75

Related questions

0 votes
1 answer 15 views
15 views
asked smith Geek 15.3k points 14 39 58
0 votes
1 answer 15 views
15 views
asked john Guru 27.1k points 31 47 92
0 votes
3 answers 27 views
27 views
asked rajesh Guru 39.1k points 10 21 31
0 votes
1 answer 29 views
0 votes
1 answer 13 views
13 views
asked rajesh Guru 39.1k points 10 21 31
...