Map集合的两种遍历方式

Map集合的遍历1-键找值

    
        Map<String,String> map = new HashMap<String, String>();
        map.put("a","java");
        map.put("b","c++");
        map.put("c","php");
        map.put("d","python");
        map.put("e","erlang");

        Set<String> set = map.keySet();

        Iterator<String> it = set.iterator();

        while (it.hasNext()){
            String key = it.next();
            String values = map.get(key);
            System.out.println(key+"=="+values);
        }

Map集合的遍历2-键值对映射关系

  Map<String,String> map = new HashMap<String, String>();
        map.put("a","java");
        map.put("b","c++");
        map.put("c","php");
        map.put("d","python");
        map.put("e","erlang");

        Set<Map.Entry<String, String>> set = map.entrySet();

        Iterator<Map.Entry<String, String>> it = set.iterator();

        while (it.hasNext()){
            Map.Entry<String, String> entry = it.next();
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"=="+value);

        }
上一篇:go流水线编程模式,它和我们熟悉的生产者-消费者模式非常相似


下一篇:OFDM系统仿真【matlab源码】