Hashmaps

Discussion in 'Plugin Development' started by crushh87, Apr 3, 2013.

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

    crushh87

    Hello!
    I have been working on a plugin recently and I found I need to use a HashMaps to store players so I can later teleport them and have them do other things. Now I have absolutely no experience using hashmaps and also have no idea what type of hashmap to use or how to store the players correctly. If some one could possibly explain this to me that would be greatly appreciated!

    - Let me know if you don't understand (It makes sense in my head)
     
  2. Offline

    ZeusAllMighty11

    Store their name.

    Code:
    Set<String>playerNames = new HashSet<String>();
    // to add : playerNames.add(name);
    // to remove : playerNames.remove(name);
    // to clear : playerNames.clear();
    
     
  3. crushh87
    Maps are key-value pairs, do you need to asign a value to a key ? I must assume key being a player's name.

    If you only need to know if a player is or is not in a list then use a Set. (you could also use a List but a Set is faster when using contains() method).
     
  4. Offline

    crushh87

    Thanks! Now may I ask what exactly is a 'Set'? I have never heard of one before.
     
  5. Offline

    chasechocolate

Thread Status:
Not open for further replies.

Share This Page