Search code examples
javalistdictionaryhashmapmultimap

How can I print HashMap<String, ArrayList<Integer>>?


I have tried this

ScreenDumpParser dump = new ScreenDumpParser();
    Map btn_bound = dump.parse();

    Iterator iterator = btn_bound.keySet().iterator();

    while (iterator.hasNext()) {
       String key = iterator.next().toString();
       List<Integer> value = btn_bound.get(key);

       System.out.println(key);
    }

but this line

List<Integer> value = btn_bound.get(key);

gives error:

Type mismatch: cannot convert from Object to List<Integer>

I need to print all the values along with the key in one single row.


Solution

  • If you want to add a value to your List you should use:

    value.add( btn_bound.get(key));

    and if the button is a list or something else you must add more then one value to your list with

    value.addRange( btn_bound.get(key));

    And if you want to get a value:

    Object foo = value.get(btn_bound.get(key));