import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
public class MapMap {
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap<String, String> java=new HashMap<String,String>();
HashMap<String, String> web=new HashMap<String,String>();
java.put("j11111", "qqqqqq");
java.put("j22222", "wwwwww");
java.put("j33333", "eeeeee");
web.put("w111111", "aaaaaa");
web.put("w222222", "sssssss");
web.put("w333333", "ddddddd");
HashMap<String,HashMap<String, String>> ban=new HashMap<String,HashMap<String, String>>();
ban.put("java班", java);
ban.put("web班", web);
fun(ban);
}
//增强行 for 循环输出
public static void fun(HashMap<String,HashMap<String, String>> ban){
//输出班级
Set<Entry<String,HashMap<String, String>>> classnameSet=ban.entrySet();
for(Entry<String,HashMap<String, String>> i:classnameSet){
String classkey = i.getKey();
HashMap<String, String> classvalue = i.getValue();
System.out.println(classkey);
//输出学生
Set<Entry<String, String>> studentset=classvalue.entrySet();
for(Entry<String, String> a:studentset){
String key = a.getKey();
String value = a.getValue();
System.out.println(key+" "+value);
}
}
}
//迭代器
public static void fun(HashMap<String,HashMap<String, String>> ban){
Set<Entry<String,HashMap<String, String>>> classnameSet=ban.entrySet();
//班级
Iterator<Entry<String,HashMap<String, String>>> it=classnameSet.iterator();
while(it.hasNext()){
Entry<String, HashMap<String, String>> next=it.next();
String claString=next.getKey();
HashMap<String, String> classMap=next.getValue();
//输出班级
System.out.println(claString);
Set<Entry<String, String>> studentset=classMap.entrySet();
Iterator<Entry<String, String>> studentIt=studentset.iterator();
while (studentIt.hasNext()) {
Entry<String, String> studentEntry=studentIt.next();
String numkey=studentEntry.getValue();
String namevalue=studentEntry.getValue();
System.out.println(numkey+" "+namevalue);
}
}
}
}
}
}