Solved List within a hashmap

Discussion in 'Plugin Development' started by PickNChew, May 23, 2014.

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

    PickNChew

    I have a list inside a hashmap and I wanted to know how I would remove something from the list. Currently I have this.
    Code:
    private HashMap<String, List<String>> challenges = new HashMap<String, List<String>>();
     
    challenges.remove(key, Arrays.asList("value"));
    
    However, remove is giving me an error.
     
  2. Offline

    MineStein

    I am just wondering, but why are you using a List inside of a HashMap?
     
  3. Offline

    AronTheGamer

    Dont use List, Use LinkedList.
    List is an Interface and cant be used as an object

    The same reason wht you use HashMap instead of Map

    This will work:

    HashMap<String, LinkedList<String>> challenges = new HashMap<String, LinkedList<String>>();

    And to remove something from the list (not the list from the hashmap)

    public void removeFromList(String HashmapString, String ListString) {
    LinkedList tempList = challenges.get(HashmapString);
    tempList.remove(ListString);
    challenges.put(HashmapString, tempList);
    tempList=nu;
    }
     
  4. Offline

    minoneer

    No, it's perfectly fine to use the List interface in the HashMap. You don't have to specify the actual Class since you're not creating it there.
     
  5. Offline

    PickNChew

    AronTheGamer I'm still using a list but thanks for the help ;)
     
Thread Status:
Not open for further replies.

Share This Page