patternjavaCritical
What are the differences between a HashMap and a Hashtable in Java?
Viewed 0 times
hashtablejavaareandbetweenthedifferenceshashmapwhat
Problem
What are the differences between a
Which is more efficient for non-threaded applications?
HashMap and a Hashtable in Java?Which is more efficient for non-threaded applications?
Solution
There are several differences between
-
-
-
One of HashMap's subclasses is
Since synchronization is not an issue for you, I'd recommend
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.Context
Stack Overflow Q#40471, score: 4265
Revisions (0)
No revisions yet.