Sort map in descending order java8 [duplicate]
问题 This question already has answers here : How to sort a LinkedHashMap by value in decreasing order in java stream? (4 answers) Closed 3 years ago . private static <K, V extends Comparable<? super V>> Map<K, V> sortByValue( Map<K, V> map ) { Map<K, V> result = new LinkedHashMap<>(); Stream<Map.Entry<K, V>> st = map.entrySet().stream(); st.sorted( Map.Entry.comparingByValue() ) .forEachOrdered( e -> result.put(e.getKey(), e.getValue()) ); return result; } This is an example from this post. It