Iterator遍历集合元素

2017-03-02  本文已影响0人  navy_legend

Iterator接口经常被称作迭代器,它是Collection接口的父接口。但Iterator主要用于遍历集合中的元素。Iterator接口中主要定义了2个方法:


 private HashMap<Integer, AreaAndCountyBean> areaAndCountyBeanCheckedList = new HashMap<>();

   List<AreaAndCountyBean> resultList = new ArrayList<>();
        Iterator iterator = areaAndCountyBeanCheckedList.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            AreaAndCountyBean checkedItem = (AreaAndCountyBean) entry.getValue();
            resultList.add(checkedItem);
        }

上一篇 下一篇

猜你喜欢

热点阅读