I currently have a HashMap that stores String and Integer and it sorts the player's depending on their kills so: Code: Player1 100 Player2 35 Player3 21 Player4 15 Player5 12 Player7 9 How would I be able to get the top player (Player1)
@AyWuzzUp Create a String variable. This stores the player with the most points/kills Create an int. This will be the amount of kills for that players. Set it to -1. For loop through all of the entries. If the kills for that value is greater than the int from #2, set the String to be equal to the player and the int to be equal to the amount of kills. Once the for loop is over, String will be equal to the player with the most kills.
This is what I have so far and it works fine, Code: File dir = new File(plugin.getDataFolder().getPath()); File[] directoryListing = dir.listFiles(); if (directoryListing != null) { for (File child : directoryListing) { userFile = YamlConfiguration.loadConfiguration(child); kills.put(userFile.getString("User.CurrentName"), userFile.getInt("User.Kills")); } kills.entrySet() .stream() .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) .limit(5) .forEach(e -> { player.sendMessage(e.getKey() + " " + e.getValue()); }); is there any way I can simply make a method or something where I can do retrieve(1) this will return the top player's name and int?