循环删除list中元素的方法

2018-06-04  本文已影响0人  清风笑_e92c

Iterator it = list.iterator();while(it.hasNext()){

    String x = it.next();

    if(x.equals("del")){

        it.remove();

    }

}

使用iterator的remove方法,如果用list的remove方法同样会报上面提到的ConcurrentModificationException错误。

上一篇 下一篇

猜你喜欢

热点阅读