import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;
public class MapDome {
// Map 嵌套存儲Map
// aaa
// java班
// 001 郭嘉
// 002 神郭嘉
// javahoodp班
// 001 黃月英
// 002 神黃月英
// java班 :存學號和名字
// javahoodp班:存學號和名字
// 學校:存的是班級
// java班<學號,姓名>
// aaaMap<班級名字,java班>
public static void main(String[] args) {
//定義Java班的集合
HashMap<String, String> java=new HashMap<String, String>();
//定義java班級的學生
java.put("001","郭嘉");
java.put("002", "神郭嘉");
//定義hdoop班的集合
HashMap<String, String> hdoop=new HashMap<String,String>();
//向hdoop班保存學生
hdoop.put("001","黃月英");
hdoop.put("002", "神黃月英");
//定義學校的集合
HashMap<String, HashMap<String, String>> a=new HashMap<String,HashMap<String, String>>();
//定義學校是容器 鍵是班級的名字 值是兩個
a.put("java班", java);
a.put("hdoop班", hdoop);
//調用集合aaa 的方法 entrySet 將學校集合的鍵封裝到Set集合中
Set<Entry<String, HashMap<String, String>>> Set=a.entrySet();
//增強for循環遍歷集合
//獲取的是學校的集合
for(Entry<String, HashMap<String, String>> s:Set){
//獲取getkey 和getvalue的值
String key = s.getKey();
HashMap<String, String> value = s.getValue();
System.out.println(key);
現在獲取的是兩個班級的集合
Set<Entry<String, String>> enSet = value.entrySet();
//使用增強for循環,循環Set集合
for(Entry<String, String>l:enSet){
String key2 = l.getKey();
String value2 = l.getValue();
System.out.println(key2+" "+value2);
}
}
System.out.println("+++++++++++++++++++++++++++++++++++");
//使用迭代 set集合
Iterator<Entry<String, HashMap<String, String>>> it = Set.iterator();
while (it.hasNext()) {
Entry<String, HashMap<String, String>> next = it.next();
String key = next.getKey();
HashMap<String, String> value = next.getValue();
Set<Entry<String, String>> enSet = value.entrySet();
Iterator<Entry<String, String>> ite = enSet.iterator();
while (ite.hasNext()) {
Entry<String, String> next2 = ite.next();
String key2 = next2.getKey();
String value2 = next2.getValue();
System.out.println(key2+" "+value2);
}
}
}
}