I am attempting to access an ArrayList within a HashMap and iterate over it. However I am currently running into an issue with the following setup.
Map<String, List<String>> map = new HashMap<String, List<String>>();
List<String> list = Arrays.asList("One", "Two", "Three");
map.put("key_one", list);
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
log.info(pair.getKey());
log.info(pair.getValue().getClass());
for (String element : pair.getValue()) {
log.info(element);
}
}
There is something with accessing the ArrayList that is giving me issues.
[ERROR] required: array or java.lang.Iterable
[ERROR] found: java.lang.Object
If I access the list outside of the map, everything works fine. Its just accessing within the HashMap.
Any guidance would be most appreciated. Thank you for your time.
Warm Regards