全体のhashMapを巡回して、hashTable


HashMapは下のフォーマットを使って、直接循環して全体のhashMapを遍歴することを発見しました。  hashTable
返したセットの各要素は、Map.Entryタイプです。
Javaコード
prvate Hashtable email = new Hashtable();  
  •   
  • /    方法1: 用ntrySet()  
  • /    Iterator it = email.entrySet().iterator()  
  • /    while(it.has Next(){  
  • /        Map.Entry m=(Map.Entry)it.next()  
  • /        logger.info("email-" + m.getKey() + ":" + m.getValue();  
  • /    }   
  •      
  •   // 方法二:直接再循環中  
  •   for (Map.Entry<String、 String> m : email.entrySet() {   
  •       logger.info("email-" + m.getKey() + ":" + m.getValue();  
  •   }   
  •      
  •   // 方法3:keySetを使う()  
  •   Iterator it = email.keySet().iterator()  
  •   while (it.has Next(){  
  •       String key;  
  •       key=(String)it.next()  
  •       logger.info("email-" + key + ":" + email.get(key)  
  •   }  
  • private Hashtable<String, String> emails = new Hashtable<String, String>();
    
    //       :  entrySet()
    //    Iterator it = emails.entrySet().iterator();
    //    while(it.hasNext()){
    //        Map.Entry m=(Map.Entry)it.next();
    //        logger.info("email-" + m.getKey() + ":" + m.getValue());
    //    }
      
      //    :      
      for (Map.Entry<String, String> m : emails.entrySet()) {
          logger.info("email-" + m.getKey() + ":" + m.getValue());
      }
      
      //    : keySet()
      Iterator it = emails.keySet().iterator();
      while (it.hasNext()){
          String key;
          key=(String)it.next();
          logger.info("email-" + key + ":" + emails.get(key));
      }
    また、まずhashMapを集合Collectionに変えてから繰り返し出力してもいいですが、得られたオブジェクトは
    Javaコード
  • Map a。 = new HashMap();      
  •  aa.put(「tmp 1」、 new Object();     //追加     同じ関数で置換します。      
  •  aa.remove("temp 1")   //削除      
  •  for(Iterator) i = a.values().iterator() i.has Next()   {      
  •       Object temp =  i.next();      
  •  }         //巡回する     
  •  Map aa = new HashMap();   
      aa.put("tmp1", new Object());     //               .   
      aa.remove("temp1");   //     
      for(Iterator i = aa.values().iterator(); i.hasNext();)   {   
           Object temp =  i.next();   
      }         //