ConcurrentModificationException

代碼邏輯:對list集合進行遍歷,有不符合要求的數據remove掉,出現bug:orm

ConcurrentModificationExceptionrem

百度知道後發現:get

你不能在對一個List進行遍歷的時候將其中的元素刪除掉
解決辦法是,你能夠先將要刪除的元素用另外一個list裝起來,等遍歷結束再remove掉
能夠這樣寫
List delList = new ArrayList();//用來裝須要刪除的元素
for(Information ia:list)
	if(ia.getId()==k){
		n++;
		delList.add(ia);
}
list.removeAll(delList);//遍歷完成後執行刪除
相關文章
相關標籤/搜索