Increment A Hashmap?

Discussion in 'Plugin Development' started by KedalionPlugins, Jul 25, 2013.

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

    KedalionPlugins

    Hey guys...

    I was curious on how you can increment a hashmap? We have one that looks like this:

    public HashMap<Player, Integer> credits = new HashMap<Player, Integer>();

    Thanks :)
     
  2. Offline

    Ewe Loon

    is this what you mean

    for (Player plr:credits.keySet()){
    //do stuff here
    }
     
  3. Offline

    KedalionPlugins

    I just meant to add one to an integer in a hashmap..
     
  4. Offline

    Ewe Loon

    credits.put(plr,credits.get(plr)+1);
     
    KedalionPlugins likes this.
  5. KedalionPlugins
    Also I'd recommend storing the player's name as a string, not the actual Player object, that causes memory leaks.
     
    KedalionPlugins likes this.
  6. Offline

    KedalionPlugins

    Thanks for the tip
     
Thread Status:
Not open for further replies.

Share This Page