Alex Rivera | Logout

Java - Iterating over a Map which contains a List

Asked 2012-04-09T15:50:16.050
8

First time here so I hope this makes sense!

I have a Map which contains a String as it's Key, and a List of Strings as it's Value. I need to iterate over all vlaues contained within each List within the Map.

So, first I want to get the Keys, which works:

Set<String> keys = theMap.keySet();

This returns me a Set containing all my Keys. Great :)

This is where I've got stuck - most of the info on the web seems to assume that the values I'd want returned from the Key would be a simple String or Integer, not another Set, or in this case a List. I tried theMap.values() but that didn't work, and I tried a forloop / for:eachloop, and neither of those did the trick.

Thanks y'all!

Edit
Report

1 Answer

0

You need a Map<String, List<String>>

The left hand side String is the key, the right hand side List<String> is the value, which in this case is a List of Strings

answered 2012-04-09T15:52:29.077

Your Answer