Here you can find the source of sortByValue( Map
public static <K, V extends Comparable<? super V>> List<Map.Entry<K, V>> sortByValue( Map<K, V> map)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static <K, V extends Comparable<? super V>> List<Map.Entry<K, V>> sortByValue( Map<K, V> map) { List<Map.Entry<K, V>> sortedEntries = new ArrayList<Map.Entry<K, V>>( map.entrySet());/* w ww . j av a2 s . co m*/ Collections.sort(sortedEntries, new Comparator<Map.Entry<K, V>>() { @Override public int compare(Map.Entry<K, V> e1, Map.Entry<K, V> e2) { return e2.getValue().compareTo(e1.getValue()); } }); return sortedEntries; } }