Online Java Compiler By
JavaTpoint.com
import java.util.IdentityHashMap; import java.util.Set; public class IdentityHashMapPutAllExample1 { public static void main(String[] args) { //Creating an object of IdentityHashMap class IdentityHashMap
map1 = new IdentityHashMap
(6); IdentityHashMap
map2 = new IdentityHashMap
(6); //Putting key-value pairs inside map1 map1.put("Java", 1); map1.put("is", 2); map1.put("the", 3); map1.put("best", 4); map1.put("programming", 5); map1.put("language", 6); //Displaying elements of map1 System.out.println(map1); //Checking if map2 is empty or not System.out.println(map2); //Copying all elements from map1 into map2 map2.putAll(map1); //Displaying elements of map2 System.out.println(map2); } }
Output