package it.may.video;
import java.util.HashMap;
import java.util.Set;
/*
* czbk
* yr :预热班 键值对 Map
* jy :就业班
*
* 预热班
* 01 zhangsan 键值对 Map
* 02 lisi
* 就业班
* 01 wangwu 键值对 Map
* 02 zhaoliu
*
* Map的嵌套。
* */
public class HashMapTest {
public static void main(String[] args) {
//创建集合对象
HashMap<String,HashMap<String,String>> czbk = new HashMap<String,HashMap<String,String>>();
//创建元素
HashMap<String,String> yr = new HashMap<String,String>();
yr.put("01", "zhangsan");
yr.put("02", "lisi");
czbk.put("yr", yr);
HashMap<String,String> jy = new HashMap<String,String>();
jy.put("01", "wangwu");
jy.put("02", "zhaoliu");
czbk.put("jy", jy);
//遍历集合
Set<String> czbkKeys = czbk.keySet();
for (String czbkKey : czbkKeys) {
System.out.println(czbkKey);
HashMap<String,String> czbkValue = czbk.get(czbkKey);
Set<String>bjKeys = czbkValue.keySet();
for (String bjKey : bjKeys) {
String bjValue = czbkValue.get(bjKey);
System.out.println(bjKey+"***"+bjValue);
}
}
}
}
|
|