迭代出错:在循环删除一个集合的数据时,不能用Collection .remove
得用Iterator .remove才行
删除对象后,集合会重新排序,会导致发生异常
正确写法:
String str = null;
while (it.hasNext()) {
str = (String) it.next();
if (deliverySet.contains(str)) {
it.remove();
} else {
tempMap.put(str, "1"); }
}
以下写法就会出现异常情况:
String str = null;
while (it.hasNext()) {
str = (String) it.next();
if (deliverySet.contains(str)) {
deliverySet.remove(str);
} else {
tempMap.put(str, "1");
}
}