Map<Integer, Map<String, List>> classAmount = new HashMap<Integer, Map<String, List>>();
现在想遍历classAmount,取出每个string的list,请问该如何遍历呢。
我试了,但是第一次遍历后取出的是Entry,无法转化到set.
现在想遍历classAmount,取出每个string的list,请问该如何遍历呢。
我试了,但是第一次遍历后取出的是Entry,无法转化到set.
调试欢乐多
public class Main {
public static void main(String[] args) {
Map <Integer, Map <String, List>> classAmount = new HashMap <Integer, Map <String, List>>();
Map<String,List> m = new HashMap<String,List>();
List l = new ArrayList();
l.add("haha");
m.put("1", l);
classAmount.put(1, m);
Set<Entry<Integer, Map<String, List>>> set = classAmount.entrySet();
Iterator<Entry<Integer, Map<String, List>>> i = set.iterator();
while(i.hasNext()) {
Entry e = i.next();
Map<String,List> map = (Map<String, List>) e.getValue();
Set<Entry<String,List>> s = map.entrySet();
Iterator<Entry<String,List>> inner = s.iterator();
while(inner.hasNext()) {
List list = (List)inner.next().getValue();
Iterator li = list.iterator();
while(li.hasNext()) {
System.out.println(li.next());
}
}
}
}
}
Map<Integer, Map<String, List>> mm = new HashMap<Integer, Map<String,List>>();
List l1 = new ArrayList();
l1.add("A");l1.add("B");l1.add("C");
List l2 = new ArrayList();
l2.add("D");l2.add("E");l2.add("F");l2.add("G");
List l3 = new ArrayList();
l3.add("H");l3.add("I");l3.add("J");
Map<String,List> m1 = new HashMap<String, List>();
m1.put("11", l1);
Map<String,List> m2 = new HashMap<String, List>();
m1.put("22", l2);
Map<String,List> m3 = new HashMap<String, List>();
m1.put("33", l3);
mm.put(111, m1);
mm.put(222, m2);
mm.put(333, m3);
Set<Integer> set = mm.keySet();
Iterator<Integer> it =set.iterator();
while(it.hasNext()){
Map<String, List> sl = mm.get(it.next());
Set<String> s = sl.keySet();
Iterator<String> it2 = s.iterator();
while(it2.hasNext()){
System.out.println(sl.get(it2.next()));
}
}
}