循环删除list中元素的方法

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

    String x = it.next();

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

        it.remove();

    }

}

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

你可能感兴趣的:(循环删除list中元素的方法)