map循环最推荐的写法
for (Map.Entry<String, Object> entry : map.entrySet()) {
// System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
}
循环删除
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> next = iterator.next();
String key = next.getKey();
iterator.remove(); // 这里注意是iterator
}
list循环删除
Iterator<String> iterator = a.iterator();
while (iterator.hasNext()) {
iterator.next(); // 这里必须要有next(),否则会报错
iterator.remove();
}