Just how do HashMaps/HashSets work

Discussion in 'Plugin Development' started by Demyxa, Apr 20, 2019.

Thread Status:
Not open for further replies.
  1. I want a list of values to be assigned to a player for a server that uses stats like "Strength" and "Athleticism" etc, the usual RPG stats.

    If I read correctly, a Hashmap is something that lets me assign a thing to a thing and then retrieve it on call, even several things to one, however I'm uncertain about the difference between HashMaps and HashSets.

    This thread is more of a "can you clear me of any mistakes or uncertainty?"
     
  2. Offline

    Shqep

    HashSet is similar to List, Set; storing keys.
    HashSet doesn’t like duplicate keys.

    HashMap stores stuff by pairs of key-value.
    HashMap doesn’t like duplicate keys, but it’s ok with duplicate values, as you said.

    Correct me if I’m wrong.

    @timtower, just asking, is this in the correct section? I feel like it should be in Plugin Development.
     
    Last edited: Apr 20, 2019
    Demyxa likes this.
  3. Offline

    Escad

    Shqeq is correct. Sets are a type of Collection, like Lists are, so its behavior is more comparable to a List than a Map.
    Also worth noting is that Set's only have a #contains method, and no #get method like a List would. They are not guaranteed to be ordered, while Lists are typically in order of insertion.

    If you're storing the individual statistics of every player, though, using a lot of Maps saying "this player has this stat" wouldn't be the most efficient or manageable. You'd be best off creating a wrapper class for Players to store that information.
     
Thread Status:
Not open for further replies.

Share This Page