I'm trying to sort a Map by it's values using JDK 8 style functions. Though I got the sorting part, I'm not sure how to collect the results in a TreeMap. Can someone explain how to get this done in declarative style?
I need to collect to another Map<String, String>
.
Map<String, String> map = new HashMap<>();
map.put("John", "time3");
map.put("Henry", "time6");
map.put("Smith", "time1");
map.put("Rock", "time2");
map.put("Ryan", "time5");
map.put("Gosling", "time4");
map.entrySet().stream()
.sorted(Map.Entry.<String, String>comparingByValue().reversed())
;