Is it possible to convert ConcurrentHashMap
to HashMap
in java ?
This is my sample program where i was converting from ConcurrentHashMap
to HashMap
but i was getting the following exception:
Exception in thread "main" java.lang.ClassCastException: java.util.concurrent.ConcurrentHashMap cannot be cast to java.util.HashMap at com.Hi.main(Hi.java:18)
My code:
package com;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class Hi {
public static void main(String args[]) {
Map<String, String> conpage = new ConcurrentHashMap<String, String>();
conpage.put("1", "A");
conpage.put("2", "B");
conpage.put("3", "C");
HashMap hm = (HashMap) conpage;
System.out.println(hm.get("1"));
}
}