ealdent (owner)

Revisions

gist: 159913 Download_button fork
public
Description:
Sort map keys by values.
Public Clone URL: git://gist.github.com/159913.git
Embed All Files: show embed
valueSortedKeys.java #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static <T, S extends Comparable<? super S>> List<T> valueSortedKeys(final Map<T, S> map)
{
  List<T> list = new ArrayList<T>(map.keySet());
 
  Collections.sort(list, new Comparator<T>()
  {
    public int compare(T t1, T t2)
    {
      return map.get(t1).compareTo(map.get(t2));
    }
  });
 
  return list;
}