Java tutorial
//package com.java2s; import java.util.*; import java.util.Map.Entry; public class Main { public static List<Entry<Long, Long>> sortEntrySetToList(Set<Entry<Long, Long>> set) { List<Entry<Long, Long>> list = new LinkedList<>(set); Collections.sort(list, new Comparator<Entry<Long, Long>>() { @Override public int compare(Entry<Long, Long> o1, 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<>(collection); Collections.sort(list, comparator); return list; } }