Hiprup

What is the difference between HashMap and Hashtable?

Both implement Map, but they target very different needs.

HashMapnot synchronized, allows one null key and many null values, faster. The default for single-threaded use.

Hashtablesynchronized (legacy), no nulls, slower. Considered obsolete; use ConcurrentHashMap for thread-safe maps.

Iteration — HashMap iterators are fail-fast; Hashtable's old Enumeration is fail-safe but considered legacy.

Always recommend ConcurrentHashMap over Hashtable for thread safety. Know the null handling difference (HashMap allows null key, Hashtable does not).

The internal implementation differences (segment locking vs method locking) show deep knowledge.

What is the difference between HashMap and Hashtable? | Hiprup