迭代器遍历MapListSet
Posted kongnengjing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了迭代器遍历MapListSet相关的知识,希望对你有一定的参考价值。
1、Map的遍历 Map<Integer,String> maps=new HashMap<Integer,String>(); maps.put(1,"a"); maps.put(2,"b"); maps.put(3,"c"); Iterator<Map.Entry<Integer,String>> itMap=map.entrySet.iterator(); while(itMap.hasNext){ Map.Entry<Integer,String> entry=itMap.next(); System.out.println(entry.getKey()+","+entry.getValue); } 2、List的遍历 List<String> lists=new ArrayList<String>(); lists.add("a"); lists.add("b"); lists.add("c"); Iterator<String> itList=lists.iterator(); while(itList.hasNext()){ String value=itList.next(); System.out.println(value); } 3、Set的遍历 Set<String> set=HashSet<String>(); set.add("a"); set.add("b"); set.add("c"); Interator itSet=set.interator(); for(itSet.hasNext()){ String value=itSet.next(); System.out.println(value); }
以上是关于迭代器遍历MapListSet的主要内容,如果未能解决你的问题,请参考以下文章
Groovy集合遍历 ( 使用集合的 reverseEach 方法进行遍历 | 倒序集合迭代器 ReverseListIterator 类简介 | 代码示例 )
用迭代器iterator遍历list中第一条数据和最后一条数据 并判断