Here you can find the source of sortByValue(final Map m)
public static List sortByValue(final Map m)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static List sortByValue(final Map m) { List keys = new ArrayList(); keys.addAll(m.keySet());/*from w w w .j a v a 2 s . co m*/ Collections.sort(keys, new Comparator() { public int compare(Object o1, Object o2) { Object v1 = m.get(o1); Object v2 = m.get(o2); if (v1 == null) { return (v2 == null) ? 0 : 1; } else if (v1 instanceof Comparable) { return -((Comparable) v1).compareTo(v2); } else { return 0; } } }); return keys; } }