Hey guys i need help with sorting my map<Player,Integer> where player is player and integer is player's kills. After end of the game, i need to display top 3 players with most kills, but dont know how to sort the map. Could you help me ?
You could get the keySet() from the Map, and loop through all the values and display the 3 highest ints after the loop is done.
java.util.Collections#sort -> java.util.Map#values EDIT + maybe java.util.Arrays#copyOfRange to get the first 3...
Literally the first link I found on Google >.< come on. You can't tell me you searched already http://www.mkyong.com/java8/java-8-how-to-sort-a-map/
Having used @2008Choco's example, you would next just need to get the first 3 entries in the LinkedHashMap. You could have some sort of counter variable and a list variable that stores the top 3 players and then begin a for loop going through the "results" LinkedHashMap using #keySet() until you have 3 results. Increment the counter variable and add to your list variable until you have 3. Next, just use the #get() method on the "results" LinkedHashMap to obtain the integer value that corresponds to a player.