From 017badd303c1436b528ba63ac5e2efca230b6eee Mon Sep 17 00:00:00 2001 From: Seshu Thanneeru Date: Wed, 19 Jan 2022 19:44:51 +0530 Subject: [PATCH] changed code to show copy-paste ready code comment --- .../map/identity/IdentityHashMapDemonstrator.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/java-collections-maps-3/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java b/java-collections-maps-3/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java index 155cdc06e7..dbd309eab3 100644 --- a/java-collections-maps-3/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java +++ b/java-collections-maps-3/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java @@ -11,7 +11,7 @@ public class IdentityHashMapDemonstrator { updateWithNewValue(copiedMap); iterateIdentityHashMap(copiedMap); addNullKeyValue(); - demoHashMapVsIdentityMap(identityHashMap); + demoHashMapVsIdentityMap(); demoMutableKeys(); Map synchronizedMap = getSynchronizedMap(); @@ -106,7 +106,13 @@ public class IdentityHashMapDemonstrator { System.out.println("IdentityHashMap: " + identityHashMap); } - private static void demoHashMapVsIdentityMap(IdentityHashMap identityHashMap) { + private static void demoHashMapVsIdentityMap() { + IdentityHashMap identityHashMap = new IdentityHashMap<>(); + identityHashMap.put("title", "Harry Potter and the Goblet of Fire"); + identityHashMap.put("author", "J. K. Rowling"); + identityHashMap.put("language", "English"); + identityHashMap.put("genre", "Fantasy"); + HashMap hashMap = new HashMap<>(identityHashMap); hashMap.put(new String("genre"), "Drama"); assert (4 == hashMap.size());