迭代器遍历map集合

    
       
    
      //通过键值对来遍历
 Iterator> iterator = map.entrySet().iterator();//返回所有的entry实体
        while (iterator.hasNext()) {
        	Map.Entry next1 = iterator.next();
        	String key = next1.getKey();
        	String value = next1.getValue();
        	System.out.println(key+" "+value);
        }
        //通过键来遍历
        Iterator  iterator1 = map.keySet().iterator();
        while (iterator1.hasNext()) {
        	System.out.println(iterator1.next());
        }
        //通过值来遍历
        Iterator iterator2 = map.values().iterator();
        while (iterator2.hasNext()) {
        	System.out.println(iterator2.next());
        }

你可能感兴趣的:(collect)