java.util.ConcurrentModificationException android after remove elements from array list

前端 未结 3 1563
别跟我提以往
别跟我提以往 2021-02-12 21:47

I have the folloing code in my android app:

/**
 * callback executed after fetching the data.
 */
public void OnPointsFetch(ArrayList result) {

             


        
3条回答
  •  一整个雨季
    2021-02-12 22:01

    You can't remove items from a list while iterating over it. You need to use an iterator and its remove method:

    for(Iterator it = result.iterator(); it.hasNext();) {
        Shop s = it.next();
        if(s.getClientPoints().getPointsSpent() == 0) {
            it.remove();
        }   
    }
    

提交回复
热议问题