Solved List within a hashmap

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

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


    I have a list inside a hashmap and I wanted to know how I would remove something from the list. Currently I have this.
    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


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


    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);
    challenges.put(HashmapString, tempList);
  4. Offline


    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


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

Share This Page