首页 > 代码库 > 遍历Map集合

遍历Map集合

HashMap<String, String> map = new HashMap<String, String>();
        map.put("京东", "刘强东");
        map.put("腾讯", "马化腾");
        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        Iterator<Map.Entry<String, String>> iterator = entrySet.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> entry = iterator.next();
            System.out.println("主键:" + entry.getKey() + ",值:" + entry.getValue());
        }

 

遍历Map集合