HashMap is sorted by value from large to small, and value is equal to the key from small to large.
[2] is from small to large sort, in the [2] code based on the exchange of O1,o2 position can be.
The code uses the method mentioned in [1] to compare key when value is equal.
Staticmap Sortbyvalue (map map) {List List=NewLinkedList (Map.entryset ()); Collections.sort (list,NewComparator () { Public intCompare (Object O1, Object O2) {if((( comparable) ((Map.entry) (O2). GetValue ()). CompareTo ((((map.entry) (O1 )). GetValue (())? =n) { return( (comparable) ((Map.entry) (O2). GetValue ()). CompareTo (((map.entry) (O1)). GetValue ()); }Else { return( (comparable) ((Map.entry) (O1). GetKey ()). CompareTo (((Map.entry) (O2)). GetKey ()); } } });
[1]key,value Simultaneous sorting http://stackoverflow.com/a/3074324/1767800
[2] Sort by value http://stackoverflow.com/a/109389/1767800
HashMap sort by value from big to small, value equals key from small to large