Getting top 10 values

Discussion in 'Plugin Development' started by mcaustin1, Nov 9, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    mcaustin1

    Hello All,

    Im curious on how to get the top ten values out of a HashMap. Any help here?

    Thanks,

    MrMcaustin1
     
  2. mcaustin1 Depends how you're sorting it.
    I'd get a list of all of the values (map.values() I think) and use Collections.sort() to order them. From there, you can get the top 10.
     
    teej107 likes this.
  3. Offline

    mcaustin1

    Map<String, Integer> OnlineKills = new HashMap<String, Integer>();
    DJSkepter

    Thats how the hashmap is used.

    In case you need the code here it is: http://pastebin.com/5cUi5XD2

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  4. Offline

    teej107

    mcaustin1

     
  5. Offline

    mcaustin1

    You cant use .sort() with a HashMap. Any other sugestions?
    teej107
    DJSkepter
     
  6. Offline

    Codex Arcanum

    The solution they were advocating was Collections.sort(map.values()) - not Collections.sort(map). Mind you - this is only an effective solution if you only need the 10 values - and not the 10 keys they were associated with.
     
  7. Offline

    mcaustin1

    Sorry this my fault I want to sort the HashMap by the integers it contains. So basically I am making a leaderboard.
     
  8. Offline

    Codex Arcanum

    OK. In that case, a HashMap is probably not the correct storage type for you.
     
  9. Offline

    mcaustin1

    What would I use then?
     
  10. Offline

    Skionz

    mcaustin1 Configs, property files, an SQL database.
     
  11. Offline

    mcaustin1

    How would you use a config?
     
  12. Offline

    Skionz

  13. Offline

    _Filip

    TreeMap
     
  14. Offline

    mcaustin1

    How would you use this?
     
  15. Offline

    _Filip

  16. Offline

    Rocoty

    A TreeMap definitely is the way to go if you constantly need to get the top 10.
     
  17. Offline

    mcaustin1

    Okay, I dont know how to use TreeMaps any examples?

    Eclipse
     
  18. Offline

    _Filip

  19. Offline

    mcaustin1

  20. Offline

    Crud41


    Don't ask to be spoon fed. There is enough documentation on Oracle's APIs to allow you to do this without someone writing your code for you.
     
  21. Offline

    mcaustin1

    Crud41
    I follow the documentation on the Oracle's API for TreeMap and it still errors out. Thats what I am asking for help.
     
  22. Offline

    Crud41

    [quote uid=90783158 name="mcaustin1" post=2880555]Crud41
    I follow the documentation on the Oracle's API for TreeMap and it still errors out. Thats what I am asking for help.[/quote]

    Then search through forums.
    <Edit by Moderator: Redacted bit url>
     
    Last edited by a moderator: Feb 11, 2017
  23. Offline

    teej107

    Errors? Prove it! I don't believe you. No one is going to help if you aren't more descriptive.
     
  24. Offline

    mcaustin1

    nvm Someone else is helping me!
     
  25. Offline

    MajorSkillage

    you would want to sort it and then simply get the top 10 values (that is all i thought of when i saw the title this is my guess :D) like you could even use a for(int i = 0; i < 11; i++){hashmap} after it is sorted (Remember this is just a guess)
     
Thread Status:
Not open for further replies.

Share This Page