Java两种简单方式遍历Map集合

来源:互联网 发布:matlab mac 2016 编辑:程序博客网 时间:2024/05/21 11:14
    // the first method to travel the map    Iterator iter = map.entrySet().iterator();    while (iter.hasNext()) {        Map.Entry<String, String> entry = (Map.Entry<String, String>) iter                .next();        String key = entry.getKey();        String value = entry.getValue();        System.out.println(key + " " + value);    }    // the second method to travel the map    Iterator iter = map.keySet().iterator();    while (iter.hasNext()) {        String key = (String) iter.next();        String value = map.get(key);        System.out.println(key + " " + value);    }

0 0