我正在迭代它时,我的数组列表的删除命令出现问题。如何解决ConcurrentModificationException
?
protected void deleteModeOfPayment(List<List<String>> AllModeOfPayment) {
int ctr=0;
List<String> thePayments =new ArrayList<String>();
Iterator<List<String>> ia=allModeOfPayment.iterator();
while(ia.hasNext()){
thePayments=ia.next();
String refOne= thePayments.get(1).toString().trim();
if(refOne.equals(referenceIdentity)){
log.d("ALVIN","ITEM TO BE DELETE FOUND");
allModeOfPayment.remove(ctr);
}
else{
ctr++;
log.d("ALVIN","ITEM TO BE DELETE NOT FOUND");}
}
}
}
答案 0 :(得分:1)
使用迭代器删除元素 -
ia.remove();