JavaEE | 集合嵌套: HashMap 嵌套 HashMap、HashMap 嵌套 ArrayList、ArrayList 嵌套 HashMap、ArrayList 嵌套ArrayList

本文探讨了JavaEE中集合的嵌套使用,包括HashMap嵌套HashMap,HashMap嵌套ArrayList,ArrayList嵌套HashMap以及ArrayList嵌套ArrayList的四种常见组合方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JavaEE | 集合嵌套 HashMap 嵌套 HashMap、HashMap 嵌套 ArrayList、ArrayList 嵌套 HashMap

  1. HashMap 嵌套 HashMap
  2. HashMap 嵌套 ArrayList
  3. ArrayList 嵌套 HashMap
  4. ArrayList 嵌套ArrayList

1. HashMap 嵌套 HashMap

		//集合嵌套 HashMap 嵌套 HashMap
        /*
        A班
            张三 20
            李四 22
        B班
            王五 21
            赵六 23
         */
        HashMap<String, Integer> subMap1 = new HashMap<>();
        subMap1.put("张三",20);
        subMap1.put("李四",22);

        HashMap<String, Integer> subMap2 = new HashMap<>();
        subMap2.put("王五",21);
        subMap2.put("赵六",23);

        HashMap<String, HashMap<String, Integer>> map = new HashMap<>();
        map.put("A班",subMap1);
        map.put("B班",subMap2);


        Set<Map.Entry<String, HashMap<String, Integer>>> entries = map.entrySet();
        for (Map.Entry<String, HashMap<String, Integer>> entry : entries) {
   
   
            String key = entry.getKey();
            System.out.println(key);
            HashMap<String, Integer> value = entry.getValue();
            Set<Map.Entry<String, Integer
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值