Here you can find the source of getSortedColors(HashMap
public static Collection<Entry<Integer, Integer>> getSortedColors(HashMap<Integer, Integer> colors)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Map.Entry; public class Main { public static Collection<Entry<Integer, Integer>> getSortedColors(HashMap<Integer, Integer> colors) { ArrayList<Entry<Integer, Integer>> colorList = new ArrayList<>(colors.entrySet()); Collections.sort(colorList, new Comparator<Entry<Integer, Integer>>() { @Override//ww w . ja va2 s .co m public int compare(final Entry<Integer, Integer> o1, final Entry<Integer, Integer> o2) { return -o1.getValue() + o2.getValue(); } }); return colorList; } }