I have Map <A, List<A>> map = new HashMap<A, List<A>>();
Say I want to print out each element in List<A> via an enhanced for loop
doing map.get(KeyOftypeA) does not return an iterable list…seems it returns a generic Object what do I do to get back the nice list i input and make it iterable?…
EDIT: Here’s the full listing of the code I am trying to run
import java.util.*;
public class StuffTag {
public static void main (String[]args){
String stuff;
List<String> tags = new ArrayList();
Map<String,List<String>> stuff_tags = new HashMap<String,List<String>>();
List<Map> list_stuff_tags = new ArrayList();
stuff="David and Goliath";
tags.add("fire");
tags.add("water");
tags.add("smoke");
tags.add("paper");
stuff_tags.put(stuff, tags);
list_stuff_tags.add(stuff_tags);
Map el =list_stuff_tags.get(0);
for(String x:el.get("David and Goliath"))
System.out.println(x);
}
}
You need to define type of
Map ele.g,Map<String,List<String>> el =list_stuff_tags.get(0);this will work for you.