Java HashMap到concurrentHashMap

Java HashMap到concurrentHashMap,java,Java,我有一个getHashMap方法返回HashMap。 我需要用HashMap填充ConcurrentHashMap(在setConcurrentHashMap中) Map<String, String> myMap = getHashMap(); TestClass.getSingleton() .setConcurrentHashMap(new ConcurrentHashMap<String, String>(myMap)); 有办法吗 示例代码: //ge

我有一个
getHashMap
方法返回
HashMap
。 我需要用
HashMap
填充
ConcurrentHashMap
(在
setConcurrentHashMap
中)

Map<String, String> myMap = getHashMap();
TestClass.getSingleton()
    .setConcurrentHashMap(new ConcurrentHashMap<String, String>(myMap));
有办法吗

示例代码:

//getHashMap return a HashMap<String, String>
Map<String, String> myMap = getHashMap();
TestClass.getSingleton().setConcurrentHashMap(ConcurrentHashMap<String, String> concurrentHashMap)
//getHashMap返回一个HashMap
Map myMap=getHashMap();
TestClass.getSingleton().setConcurrentHashMap(ConcurrentHashMap ConcurrentHashMap)
快速查看显示,
ConcurrentHashMap
有一个复制构造函数,该构造函数将映射作为参数:

Map<String, String> myMap = getHashMap();
ConcurrentMap<String, String> concurrentMap = new ConcurrentHashMap<> (myMap);
Map myMap=getHashMap();
ConcurrentMap ConcurrentMap=新的ConcurrentHashMap(myMap);
快速查看显示,
ConcurrentHashMap
有一个复制构造函数,该构造函数将映射作为参数:

Map<String, String> myMap = getHashMap();
ConcurrentMap<String, String> concurrentMap = new ConcurrentHashMap<> (myMap);
Map myMap=getHashMap();
ConcurrentMap ConcurrentMap=新的ConcurrentHashMap(myMap);

ConcurrentHashMap
类提供了一个构造函数,用于从给定的
映射创建
ConcurrentHashMap

Map<String, String> myMap = getHashMap();
TestClass.getSingleton()
    .setConcurrentHashMap(new ConcurrentHashMap<String, String>(myMap));
Map myMap=getHashMap();
TestClass.getSingleton()
.setConcurrentHashMap(新ConcurrentHashMap(myMap));

ConcurrentHashMap
类提供了一个构造函数,用于从给定的
映射创建
ConcurrentHashMap

Map<String, String> myMap = getHashMap();
TestClass.getSingleton()
    .setConcurrentHashMap(new ConcurrentHashMap<String, String>(myMap));
Map myMap=getHashMap();
TestClass.getSingleton()
.setConcurrentHashMap(新ConcurrentHashMap(myMap));