Here you can find the source of getSortedHashMapKeyset(Map
public static <T> List<T> getSortedHashMapKeyset(Map<T, Integer> sorting)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { public static <T> List<T> getSortedHashMapKeyset(Map<T, Integer> sorting) { List<T> types = new ArrayList<>(); Map<T, Integer> clone = new HashMap<>(); for (T player : sorting.keySet()) { clone.put(player, sorting.get(player)); }/*from ww w .j ava2 s . com*/ for (int i = 0; i < sorting.size(); i++) { int highestNumber = Integer.MIN_VALUE; T highestType = null; for (T player : clone.keySet()) { if (clone.get(player) > highestNumber) { highestNumber = clone.get(player); highestType = player; } } clone.remove(highestType); types.add(highestType); } return types; } }