Map<String, Integer> maps = new HashMap<>();
maps.put("clothes", 120);
maps.put("grocery", 150);
maps.put("transportation", 100);
maps.put("utility", 130);
maps.put("rent", 1150);
maps.put("miscellneous", 90);
System.out.println("map before sorting: " + maps);
List<Entry<String, Integer>> listMap = maps.entrySet().stream()
.sorted(Map.Entry.<String, Integer>comparingByValue()).collect(Collectors.toList());
System.out.println("map after sorting by keys: " + listMap);
Map<String, Integer> maps = new HashMap<>();
maps.put("clothes", 120);
maps.put("grocery", 150);
maps.put("transportation", 100);
maps.put("utility", 130);
maps.put("rent", 1150);
maps.put("miscellneous", 90);
System.out.println("map before sorting: " + maps);
List<Entry<String, Integer>> listMap = maps.entrySet().stream()
.sorted(Map.Entry.<String, Integer>comparingByValue()).collect(Collectors.toList());
System.out.println("map after sorting by keys: " + listMap);