在遍历列表时,我希望根据某个条件从列表中删除一个项目。请参见以下代码。
这会给我一个ConcurrentModification
异常。
for (Object a : list) {
if (a.getXXX().equalsIgnoreCase("AAA")) {
logger.info("this is AAA........should be removed from the list ");
list.remove(a);
}
}
这该怎么做呢?