Java tutorial
//package com.java2s; import java.util.*; public class Main { public static List<Map.Entry<Long, Long>> sortEntrySetToList(Set<Map.Entry<Long, Long>> set) { List<Map.Entry<Long, Long>> list = new LinkedList<Map.Entry<Long, Long>>(set); Collections.sort(list, new Comparator<Map.Entry<Long, Long>>() { @Override public int compare(Map.Entry<Long, Long> o1, Map.Entry<Long, Long> o2) { if (o1.getValue() > o2.getValue()) return 1; if (o1.getValue() < o2.getValue()) return -1; return 0; } }); return list; } public static <T> List<T> sort(Collection<T> collection, Comparator<T> comparator) { List<T> list = new ArrayList<T>(collection); Collections.sort(list, comparator); return list; } }