importjava.util.HashMap;importjava.util.Iterator;importjava.util.Map;importjava.util.Set;/** Map集合的嵌套,Map中存储的还是Map集合
* 要求:
* 传智播客
* Java基础班
* 001 张三
* 002 李四
*
* Java就业班
* 001 王五
* 002 赵六
* 对以上数据进行对象的存储
* 基础班Map
* 就业班Map
* 传智播客Map */
public classTestMapMap {public static voidmain(String[] args) {
HashMap javaSEmap = new HashMap();
javaSEmap.put("001", "张三");
javaSEmap.put("002", "李四");
HashMap javaEEmap = new HashMap();
javaEEmap.put("001", "王五");
javaEEmap.put("002", "赵六");
HashMap> czmap = new HashMap>();
czmap.put("基础班", javaSEmap);
czmap.put("就业班", javaEEmap);
Set>> classNameSet =czmap.entrySet();
Iterator>> classNameit =classNameSet.iterator();while(classNameit.hasNext()){
Map.Entry> classEntry =classNameit.next();
String classNameKey=classEntry.getKey();
HashMap classMap =classEntry.getValue();
Set> studentSet =classMap.entrySet();
Iterator> studentIt =studentSet.iterator();while(studentIt.hasNext()){
Map.Entry studentEntry =studentIt.next();
String skey=studentEntry.getKey();
String svalue=studentEntry.getValue();
System.out.println( classNameKey+ "_" +skey+ "_"+svalue);
}
}
}
}