在java中从列表中删除项目 [英] removing items from list in java

查看:85
本文介绍了在java中从列表中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在循环列表时,我要根据以下条件删除列表中的项目

While looping through a list, I would like to remove an item of a list depending on a condition as below

这给了我 concurrentModification exception

This is giving me concurrentModification exception

for(Object a: list){
    if(a.getXXX().equalsIgnoreCase("AAA")){
        logger.info("this is AAA........should be removed from the list ");
        list.remove(a);

    }
}

p>

推荐答案

您需要使用 Iterator 并调用 ()

这篇关于在java中从列表中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆