[Java] The difference between hashMap and hashTable

HashMap Hashtable all implement the Map interface

HashMap is non-synchronized, Hashtable is synchronized

HashMap uses Iterator, Hashtable uses Enumeration

Hashtable directly uses the object's hashcode, hashmap recalculates the hash value, and uses and instead of modulo.


In the environment of JDK 1.5 and higher versions, how can thread-safe map be implemented?

Map map = new ConcurrentHashMap();

Map map = Collections.synchronizedMap(new HashMap());

Guess you like

Origin blog.csdn.net/michellechouu/article/details/48751745