public static < K extends Comparable < K > , V extends Comparable < V > > List < Map . Entry < K , V > > sortByValueAndKey ( Map < K , V > map ) { List < Map . Entry < K , V > > entries = new ArrayList <> ( map . entrySet ( ) ) ; entries . sort ( new ByValueAndKey <> ( ) ) ; return entries ; }
Sorts the provided Map by the value and then by key instead of by key like TreeMap does .