diff --git a/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java b/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java index cd81f61b48..e1649f593c 100644 --- a/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java +++ b/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java @@ -19,29 +19,29 @@ public class CopyHashMap { } public static HashMap copyUsingPut(HashMap originalMap) { - HashMap copyMap = new HashMap(); + HashMap shallowCopy = new HashMap(); Set> entries = originalMap.entrySet(); for(Map.Entry mapEntry: entries) { - copyMap.put(mapEntry.getKey(), mapEntry.getValue()); + shallowCopy.put(mapEntry.getKey(), mapEntry.getValue()); } - return copyMap; + return shallowCopy; } public static HashMap copyUsingPutAll(HashMap originalMap) { - HashMap copyMap = new HashMap(); - copyMap.putAll(originalMap); + HashMap shallowCopy = new HashMap(); + shallowCopy.putAll(originalMap); - return copyMap; + return shallowCopy; } public static HashMap copyUsingJava8Stream(HashMap originalMap) { Set> entries = originalMap.entrySet(); - HashMap copyMap = (HashMap) entries + HashMap shallowCopy = (HashMap) entries .stream() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - return copyMap; + return shallowCopy; } public static HashMap shallowCopy(HashMap originalMap) { diff --git a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java b/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java index c71e17e94e..400696d97a 100644 --- a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java +++ b/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java @@ -68,9 +68,9 @@ public class CopyHashMapUnitTest { .put("emp1",emp1) .put("emp2",emp2) .build(); - Map mapCopy = ImmutableMap.copyOf(map); + Map shallowCopy = ImmutableMap.copyOf(map); - assertThat(mapCopy).isSameAs(map); + assertThat(shallowCopy).isSameAs(map); }