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);
}