六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 36|回复: 0

HashMap 中放 HashMap的相关取值

[复制链接]

升级  30.8%

206

主题

206

主题

206

主题

进士

Rank: 4

积分
654
 楼主| 发表于 2013-1-26 12:44:23 | 显示全部楼层 |阅读模式
// 通过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());
                 }
          }
       
     }
 }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表