Solved How to add to hashmap

Discussion in 'Plugin Development' started by slater96, Aug 25, 2013.

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

    slater96

    public Map<String, List<String>> ffaPlaying = new HashMap<String, List<String>>();

    I want to add player names to the List<String> but I'm not sure how to. Anyone know how? Thanks
     
  2. Offline

    Skyost

    ffaPlaying.put(Key, Value)
     
  3. Offline

    slater96

    Skyost
    If I try and do that with
    Code:
    plugin.ffaPlaying.put("Test", p.getName());
    Then is says 'The method put(String, List<String>) in the type Map<String,List<String>> is not applicable for the arguments (String, String)'
     
  4. Offline

    Stoux

    I think you get the whole point of a HashMap wrong. All you need is the List<String>?
    Code:java
    1. public List<String> ffaPlaying = new ArrayList<>();
    2.  
    3. ffaPlaying.add(p.getName);
     
  5. Offline

    slater96

    It's just that I'm trying to store the key as an arena, then the list of players who are in an arena. Can you not use a hashmap with a list string in it?
     
  6. Offline

    Rocoty

    Code:java
    1. List<String> players = ffaPlaying.get("arena");
    2. players.add(ply.getName());
    3. ffaPlaying.put("arena", players);


    But...make life easier for yourself and make an Arena class

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
    slater96 likes this.
Thread Status:
Not open for further replies.

Share This Page