Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.ConcurrentHashMap; import java.util.*; public class ConcurrentHashMapclearExample2 { public static void main(String[] args) { Map
chm2 = new ConcurrentHashMap
(); //put is used to add value to map //map can also have string as key chm2.put("a", "1"); chm2.put("b", "10"); chm2.put("c", "100"); chm2.put("d", "2"); chm2.put("e", "20"); chm2.put("f", "200"); System.out.println("Values in map: \n" + chm2); chm2.clear(); // clear will clear all the values in map. System.out.println("Map after calling clear(): " + chm2); } }
Output