Need help with HashMaps

Discussion in 'Plugin Development' started by DutchChris, May 14, 2020.

  1. Offline



    I recently made a post about players and variables and how I should store them and I was told HashMaps were the way to go. Sadly, I don't really know how to use HashMaps with Players. For example, how would I make a HashMap that stores player stats(levels & xp) so every player has their own stats? Thanks for the help!

    - DutchChris_
  2. Online

    timtower Moderator Moderator

  3. Offline


    @timtower how would I then put stuff in for each player?
  4. Online

    timtower Moderator Moderator

  5. Offline


    HashMaps aren't too difficult, you can create one by using
    HashMap<UUID,OtherClass> map = new HashMap<UUID,OtherClass>();
    Then simply add things to it:
    map.put(player.getUniqueId(), object_of_other_class);
    To get the object back:
    OtherClass object_of_other_class = map.get(player.getUniqueId());
    Check out the HashMap docs to see all the methods you can use on them:

Share This Page