How would you sort a hashmap into a leaderboard of top 10?
Please leave ideas.
Please leave ideas.
If you used parallel it'd be pretty niceJava 8
Code:public List<PlayerFaction> getTopFactions(int i) { return playerFactions().stream().sorted(Comparator.comparingInt(PlayerFaction::getOnlineSize)).limit(i).collect(Collectors.toList()); }
Thank youI'd suggest using a TreeMap. A TreeMap implements a SortedMap and NavigatableMap. This means, when items are added to the TreeMap, they will hold their natural order. A HashMap however, you cannot guarantee the map will hold its order. Essentially, If you are sorting, it is highly suggested that you use a TreeMap as the order will be pure and entirely up to you on how its sorted.

