HashMap迭代的几种方式

    技术2025-01-16  17

    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));      }

    from: http://hi.baidu.com/earth_it/blog/item/833b74092e89a2c73bc763a7.html/cmtid/26b159ed8c89e2d9b21cb16a

    最新回复(0)