jackroomage 发表于 2013-1-26 12:44:23

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());
                 }
          }
       
     }
 }
页: [1]
查看完整版本: HashMap 中放 HashMap的相关取值