diff --git a/core-java-collections/src/main/java/com/baeldung/sort/SortHashMap.java b/core-java-collections/src/main/java/com/baeldung/sort/SortHashMap.java index f7ea2f655b..38eddc6cf3 100644 --- a/core-java-collections/src/main/java/com/baeldung/sort/SortHashMap.java +++ b/core-java-collections/src/main/java/com/baeldung/sort/SortHashMap.java @@ -21,12 +21,15 @@ public class SortHashMap { arrayListSortByValue(); arrayListSortByKey(); - treeSetByKey(); - treeSetByValue(); - sortStream(); sortGuava(); + + addDuplicates(); + + treeSetByKey(); + treeSetByValue(); + } private static void sortGuava() { @@ -63,10 +66,7 @@ public class SortHashMap { TreeMap sorted = new TreeMap<>(map); sorted.putAll(map); - for (Map.Entry entry : sorted.entrySet()) { - System.out.println("Key = " + entry.getKey() + - ", Value = " + entry.getValue()); - } + sorted.entrySet().forEach(System.out::println); } @@ -94,4 +94,11 @@ public class SortHashMap { Employee employee4 = new Employee(2L, "George"); map.put(employee4.getName(), employee4); } + + private static void addDuplicates() { + Employee employee5 = new Employee(1L, "Mher"); + map.put(employee5.getName(), employee5); + Employee employee6 = new Employee(22L, "Annie"); + map.put(employee6.getName(), employee6); + } }