I have a
HashMap<String,Integer> map which i want to sort in descending order by value I do:
HashMap<String,Integer> topSorted = new HashMap<>(); //sort map in descending order Stream<HashMap.Entry<String,Integer>> st = map.entrySet().stream(); st.sorted(Comparator.comparing((HashMap.Entry<String,Integer> e) -> e.getValue()).reversed()) .forEach(e -> topSorted.put(e.getKey(),e.getValue())); But topsorted is still the same as map no sorting is done at all
Can someone explain what i am doing wrong
comparingByValue(Comparator.reverseOrder())…