UnsupportedOperationException when using iterator.remove()

前端 未结 3 1501
情深已故
情深已故 2020-12-25 14:20

I\'m trying to remove some elements from a List, but even the simplest examples, as the ones in this answer or this, won\'t work.

public static          


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-25 14:30

    Create a new list with the elements you want to remove, and then call removeAll methode.

    List toRemove = new ArrayList();
    for(Object a: list){
        if(true){
            toRemove.add(a);
        }
    }
    list.removeAll(toRemove);
    
        

    提交回复
    热议问题