diff --git a/core-java-8/src/test/java/com/baeldung/shufflingcollections/ShufflingCollectionsUnitTest.java b/core-java-8/src/test/java/com/baeldung/shufflingcollections/ShufflingCollectionsUnitTest.java index 4823c7178a..d013907c9a 100644 --- a/core-java-8/src/test/java/com/baeldung/shufflingcollections/ShufflingCollectionsUnitTest.java +++ b/core-java-8/src/test/java/com/baeldung/shufflingcollections/ShufflingCollectionsUnitTest.java @@ -22,7 +22,7 @@ public class ShufflingCollectionsUnitTest { } @Test - public void whenShufflingMapKeys_thenValuesAreShuffled() { + public void whenShufflingMapEntries_thenValuesAreShuffled() { Map studentsById = new HashMap<>(); studentsById.put(1, "Foo"); studentsById.put(2, "Bar"); @@ -32,12 +32,12 @@ public class ShufflingCollectionsUnitTest { System.out.println("Students before shuffling:"); System.out.println(studentsById.values()); - List shuffledStudentIds = new ArrayList<>(studentsById.keySet()); - Collections.shuffle(shuffledStudentIds); + List> shuffledStudentEntries = new ArrayList<>(studentsById.entrySet()); + Collections.shuffle(shuffledStudentEntries); - List shuffledStudents = shuffledStudentIds.stream() - .map(id -> studentsById.get(id)) - .collect(Collectors.toList()); + List shuffledStudents = shuffledStudentEntries.stream() + .map(Map.Entry::getValue) + .collect(Collectors.toList()); System.out.println("Students after shuffling"); System.out.println(shuffledStudents);