Skip to content

Instantly share code, notes, and snippets.

@ealdent
Created August 2, 2009 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ealdent/159913 to your computer and use it in GitHub Desktop.
Save ealdent/159913 to your computer and use it in GitHub Desktop.
Sort map keys by values.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment