HashMap 中放 HashMap的相关取值

// 通过map3求出map1中的key和value


public class TestMap8 {
 public static void main(String arg[]) {
        Set hs=new HashSet();

        Set hs2=new HashSet();
      
        Map  map1 = new HashMap();
        map1.put("a", 1);
        map1.put("b", 2);
       
        Map  map2 = new HashMap();
        map2.put("c", map1);
        map2.put("d", map1);
       
        Map  map3 = new HashMap();
        map3.put("e", map2);
        map3.put("f", map2);
       
        Iterator ite=map3.entrySet().iterator();
        while(ite.hasNext()){
         Entry entry=(Entry)ite.next();
         hs.add(entry.getValue());
        }
       
          Iterator ite2= hs.iterator();
          while(ite2.hasNext()){
           HashMap ms=(HashMap)ite2.next();
          
           Iterator ite3=ms.entrySet().iterator();
           while(ite3.hasNext()){
            Entry Entry2=(Entry)ite3.next();
            hs2.add(Entry2.getValue());
             }
          }
         
          Iterator ite5=hs2.iterator();
          while(ite5.hasNext()){
           HashMap hh=(HashMap)ite5.next();
           Iterator ite6=hh.entrySet().iterator();
                 while(ite6.hasNext()){
                  Entry entry=(Entry)ite6.next();
                  System.out.print(entry.getKey()+" / ");
                  System.out.println(entry.getValue());
                 }
          }
       
     }
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值