如何线程安全的使用HashMap

2025-05-17 17:32:01
推荐回答(1个)
回答1:

//Hashtable
MapString> hashtable = new
Hashtable<>();
//synchronizedMap
MapString> synchronizedHashMap = Collections.synchronizedMap(new
HashMap());
//ConcurrentHashMap
MapString> concurrentHashMap = new
ConcurrentHashMap<>();