What are the differences between a HashMap and a Hashtable in Java?
Which is more efficient for non-threaded applications?
HashMap
: An implementation of the Map
interface that uses hash codes to index an array.
Hashtable
: Hi, 1998 called. They want their collections API back.
Seriously though, you're better off staying away from Hashtable
altogether. For single-threaded apps, you don't need the extra overhead of synchronisation. For highly concurrent apps, the paranoid synchronisation might lead to starvation, deadlocks, or unnecessary garbage collection pauses. Like Tim Howland pointed out, you might use ConcurrentHashMap
instead.