Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.*; import java.util.*; public class ConcurrentHashMapputIfAbsentExample2 { public static void main(String[] args) { // crete a HashMap and add some values HashMap
mapcon = new HashMap<>(); mapcon.put("k1", 100); mapcon.put("k2", 200); mapcon.put("k3", 300); mapcon.put("k4", 400); System.out.println("HashMap values :\n " + mapcon.toString()); mapcon.putIfAbsent("k5", 300); mapcon.putIfAbsent("k6", 10); System.out.println("New HashMap after putIfAbsent :\n "+ mapcon); } }
Output