使用Iterator遍历

  LinkedHashMap<String,String> linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("a", "a");
        linkedHashMap.put("b", "b");
        linkedHashMap.put("c", "c");
        Iterator it = linkedHashMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            System.out.println("key:" + entry.getKey() + "   value:" + entry.getValue());
        }

foreach循环遍历

 LinkedHashMap<String,String> linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("a", "a");
        linkedHashMap.put("b", "b");
        linkedHashMap.put("c", "c");
        for(Map.Entry<String, String> entry : linkedHashMap.entrySet()) {
            System.out.println("key:" + entry.getKey() + "   value:" + entry.getValue());
        }
Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐