Make a list of all players who are in a HashMap.

Discussion in 'Plugin Development' started by lifebearups, Nov 14, 2012.

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

    lifebearups

    If a player enters a command he is added to a HashMap, and soon after, and then a command takes all players within the hashmap and turns it into a list. How do I list all players who are in the HashMap?

    Thankz ;D
     
  2. Offline

    wristdirect

    If the players are the keys to the HashMap,
    Code:
    HashSet<Player> playerList = new HashSet<Player>();
    playerList.addAll(hashMapThing.keySet());
     
  3. Offline

    lifebearups

    Thanks :D It worked
     
  4. Offline

    thehutch

    Correction:
    Code:java
    1. Map<String, String> playerMap = new HashMap<String, String>();
    2. List<String> playerList = new ArrayList<String>();
    3. playerList.addAll(playerMap.keySet());


    You should never put the Player object into a HashMap because when the player dies that object becomes null and reflects in the map, so therefore you store the players name.
    Secondly you wrote a HashSet, Not a HashMap :p
     
    blackwolf12333 likes this.
Thread Status:
Not open for further replies.

Share This Page