【HashMap 嵌套 HashMap】

package com.yjf.esupplier.common.test;

import java.util.HashMap;
import java.util.Set;

/**
 * @author shusheng
 * @description HashMap 嵌套 HashMap
 * @Email shusheng@yiji.com
 * @date 2018/12/18 14:46
 */
public class HashMapDemo2 {

    public static void main(String[] args) {
        HashMap<String, HashMap<String, Integer>> doubleMap = new HashMap<String, HashMap<String, Integer>>();

        // 建立基礎班集合對象
        HashMap<String, Integer> jcMap = new HashMap<String, Integer>();
        // 添加元素
        jcMap.put("陳玉樓", 20);
        jcMap.put("高躍", 22);
        // 把基礎班添加到大集合
        doubleMap.put("jc", jcMap);

        // 建立就業班集合對象
        HashMap<String, Integer> jyMap = new HashMap<String, Integer>();
        // 添加元素
        jyMap.put("李傑", 21);
        jyMap.put("曹石磊", 23);
        // 把基礎班添加到大集合
        doubleMap.put("jy", jyMap);

        //遍歷集合
        Set<String> oneMapSet = doubleMap.keySet();
        for (String mapKey : oneMapSet) {
            System.out.println(mapKey);
            HashMap<String, Integer> mapValue = doubleMap.get(mapKey);
            Set<String> twoMapValueSet = mapValue.keySet();
            for (String mapValueKey : twoMapValueSet) {
                Integer mapValueValue = mapValue.get(mapValueKey);
                System.out.println("\t" + mapValueKey + "---" + mapValueValue);
            }
        }
    }

}
相關文章
相關標籤/搜索