day28 增强for循环进行Map嵌套Map

package zuoye;

import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;

public class zuoye {
public static void main(String[] args){
HashMap<Integer,String> a=new HashMap<Integer,String>();
HashMap<Integer,String> b=new HashMap<Integer,String>();
a.put(1,"sdaf");
a.put(2,"sdff");
b.put(1,"sdff");
b.put(2,"sdff");
HashMap<String,HashMap<Integer,String>> c=new HashMap<String,HashMap<Integer,String>>();
c.put("java",a);
c.put("c语言",b);
fu(c);
}
public static void fu(HashMap<String,HashMap<Integer,String>> c){
Set<Entry<String, HashMap<Integer, String>>> d = c.entrySet();
for(Entry<String, HashMap<Integer, String>> i:d){
String key = i.getKey();
System.out.println(key);
HashMap<Integer, String> value = i.getValue();
Set<Entry<Integer, String>> key1 = value.entrySet();
for(Entry<Integer, String> j:key1){
Integer key2 = j.getKey();
String value2 = j.getValue();
System.out.println(key2+" "+value2);
//System.out.println(j);
}
}
}
}

原文地址:https://www.cnblogs.com/hfew/p/10579226.html