for(int i = 0,n = ids.length;i<n;i++){
int id = Integer.parseInt(ids[i]);
for(int j =0;j <stockApplyDetailList.size();j++){
WhStockapplydetail detail = stockApplyDetailList.get(j);
System.out.println("id:"+id +"------detail:"+detail.getId());
if(id == detail.getId()){
stockApplyDetailList.remove(detail);
}
}
}
总是报数组下标异常,后来找了一下原因,是和list的remove方法有关,List每remove掉一个元素以后,后面的元素都会向前移动
解决方法:倒过来遍历list
for(int i = 0,n = ids.length;i<n;i++){
int id = Integer.parseInt(ids[i]);
for(int j =stockApplyDetailList.size()-1;j >= 0;j--){
WhStockapplydetail detail = stockApplyDetailList.get(j);
System.out.println("id:"+id +"------detail:"+detail.getId());
if(id == detail.getId()){
stockApplyDetailList.remove(detail);
}
}
}
用这种方式就好了,呵呵