List批量删除 因为删除了一个 下标越界了 这个时候该怎么判断呢??
6条回答 默认 最新
- zcx929666 2016-09-11 14:42关注
String[] indexs=index.split(",");//用逗号分割 System.out.println("删除多个:"+index); int tempIndex=0; int preIndex=0; for (int i = 0; i < indexs.length; i++) { tempIndex=Integer.parseInt(indexs[i]); System.out.println("tempIndex1:"+tempIndex); System.out.println("preIndex:"+preIndex); tempIndex=tempIndex-preIndex; if(preIndex==1){//说明是最后一个了 tempIndex=0; } System.out.println("tempIndex2:"+tempIndex); int pid=cartList.get(tempIndex).getPid(); System.out.println("产品名称:"+cartList.get(tempIndex).getPname()); cartList.remove(tempIndex);//先移除List中的数据 cartMap.remove(pid);//根据id移除map中的数据 preIndex=tempIndex; }
解决 无用评论 打赏 举报