Sort a HashMap

Discussion in 'Plugin Development' started by ThrustLP, Aug 4, 2016.

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

    ThrustLP

    Hey guys! I've got a question:

    I have got a HashMap:
    Code:
    HashMap<String, Integer> temp = new HashMap<String, Integer>();
    Now I want to sort this HashMap and send a player a List based of the Integer.

    So if my entries are:

    Code:
    temp.put("Tho", 2);
                            temp.put("One", 1);
                            temp.put("Four", 4);
                            temp.put("Three", 3);
    And I want to display the Player:

    One -- 1
    Two -- 2
    Three -- 3
    Four -- 4


    How would I do that?
     
  2. Online

    timtower Administrator Administrator Moderator

    @ThrustLP My first suggestion would be a bubble sort.
    However I know that there are better methods to do so, somebody will come along and post them.
     
  3. Offline

    ThrustLP

    @AlvinB Hmm okay but using it I get an error at:

    Code:
    List<Entry<String, Integer>> entryList = this.tempo.entryList();
    At entryList() saying The method entryList() is undefinded for the type SortedMap<String>
     
Thread Status:
Not open for further replies.

Share This Page