public static < K , V > Map < K , V > sortNumberMapByValueDescending ( Map < K , V > map ) { ArrayList < Map . Entry < K , V > > entries = new ArrayList <> ( map . entrySet ( ) ) ; Collections . sort ( entries , ( Map . Entry < K , V > a , Map . Entry < K , V > b ) -> { Double va = TypeInference . toDouble ( a . getValue ( ) ) ; Double vb = TypeInference . toDouble ( b . getValue ( ) ) ; return - va . compareTo ( vb ) ; } ) ; Map < K , V > sortedMap = new LinkedHashMap <> ( ) ; for ( Map . Entry < K , V > entry : entries ) { sortedMap . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } return sortedMap ; }
Sorts by Value a Map in descending order .