List集合与Map集合的遍历

                      
     /*List集合赋值*/
        List<String> strList = new ArrayList<String>();
        strList.add("1");
        strList.add("2");
        strList.add("3");
        strList.add("4");
        strList.add("5");
        /*List集合遍历*/
        Iterator<String> it = strList.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }
        
        /*Map集合赋值*/
        Map<String, String> strMap = new HashMap<String, String>();
        strMap.put("1", "测试一");
        strMap.put("2", "测试二");
        strMap.put("3", "测试三");
        strMap.put("4", "测试四");
        strMap.put("5", "测试五");
        /*Map集合遍历*/
        for(Map.Entry<String, String> entry : strMap.entrySet()){
            System.out.println("key= " + entry.getKey() + " and value= "
                                       + entry.getValue());
        }

 

posted on 2017-04-14 09:02  emmeet  阅读(131)  评论(0编辑  收藏  举报

导航