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