HashMap help

Discussion in 'Plugin Development' started by messageofdeath, Dec 7, 2012.

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

    messageofdeath

    How would you remove something from the ArrayList while its in the HashMap and the HashMap will update with this

    Code:java
    1. public static HashMap<String, ArrayList<String>> gamePlayers = new HashMap<String, ArrayList<String>>();
     
  2. Offline

    RealDope

    Code:JAVA
    1.  
    2. ArrayList<String> list = gamePlayers.get("Some string that you have as a KEY in your hashmap");
    3. list.remove(indexInt);
    4. // If you need to get the index int of a certain string use:
    5. list.indexOf("string");
    6.  
    7. // Then put back into your HashMap:
    8. gamePlayers.put("same as KEY from higher up", list);
    9.  
     
  3. Offline

    messageofdeath

    would this work

    Code:java
    1. public static void removePlayer(String name, String gameID) {
    2. for(ArrayList<String> list : gamePlayers.values()) {
    3. for(String d : list) {
    4. if(d.equalsIgnoreCase(name)) {
    5. list.add(name);
    6. gamePlayers.remove(gameID);
    7. gamePlayers.put(gameID, list);
    8. return;
    9. }
    10. }
    11. }
    12. }
     
Thread Status:
Not open for further replies.

Share This Page