Answer
HashMap and Hashtable are hash-based maps with different legacy and synchronization behavior. • Hashtable methods are synchronized and reject null keys and values. • HashMap is unsynchronized and permits one null key and null values. • ConcurrentHashMap is usually preferred for scalable concurrent access.
Example
Code
var map = new java.util.HashMap<String, Integer>(); map.put(null, 1); System.out.println(map.get(null));
Output
1
Quick Revision
HashMap is modern and unsynchronized; Hashtable is legacy synchronized storage.