package com.oracle.demo01;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;public classDemo7 {public static voidmain(String[] args) {//大map
HashMap> oracle = new HashMap>();//小map
HashMap java1018 = new HashMap();
HashMap java1227 = new HashMap();//封装集合 //给小map赋值 用put关键字
java1018.put(new Person("C罗", 34), "踢足球");
java1018.put(new Person("詹姆斯", 35), "打篮球");
java1227.put(new Person("张继科", 28), "打乒乓球");
java1227.put(new Person("朱婷", 22), "打排球");
oracle.put("java1018", java1018); //给大map赋值 同样用put关键字
oracle.put("java1227", java1227);//entryset +iterator遍历//1.获取大的Map的大结婚猪呢个对象Set集合
Set>> bigentrys =oracle.entrySet();//上面大map里面写的泛型是什么这里就写什么
Iterator>> it =bigentrys.iterator();while(it.hasNext()) {
Map.Entry> bigentry =it.next();
String bigkey=bigentry.getKey(); //获取大对象key值
HashMap smallMap =bigentry.getValue(); //获取大对象value值
Set> entrySet =smallMap.entrySet(); //创建小对象集合
Iterator> sit =entrySet.iterator();while(sit.hasNext()) {
Entry e =sit.next();
System.out.println(bigkey + "..." + e.getKey() + "..." +e.getValue());
}
}
System.out.println("=========================");//2. entryset 增强for遍历
Set>> entrySet =oracle.entrySet();for (Entry>e : entrySet) {
String bigKey=e.getKey();
HashMap hashMap =e.getValue();
Set> entrySet2 =hashMap.entrySet();for (Entrye5 : entrySet2) {
System.out.println(bigKey + "..." + e5.getKey() + "..." +e5.getValue());
}
}
System.out.println("3.增强for=========================");//3.增强for+keyset方法
Set keySet =oracle.keySet();for(String s : keySet) {
HashMap h = oracle.get(s);
Set h2 =h.keySet();for(Person p : h2) {
System.out.println(s + "..." + p + "..." + h.get(p));
}
}
System.out.println("4.迭代器=========================");
//4. 迭代器+keyset方法
Set keySet2 =oracle.keySet();
Iterator ite =keySet2.iterator();while(ite.hasNext()) {
String s=ite.next();
HashMap hashMap = oracle.get(s);
Set keySet3 =hashMap.keySet();
Iterator it8 =keySet3.iterator();while(it8.hasNext()) {
Person p1=it8.next();
System.out.println(s + "..." + p1 + "..." + hashMap.get(p1));
}
}}
}