1、使用原始for循环
for(int i =0 ; i<intList.size() ; i++){
if(intList.het(i) == 13){
intList.remove(i);
i--;
}
}
2、使用迭代器(官方推荐)
Iterator<Integer> it = intList.iterator();
where(it.hasNext()){
if(it.next() == 13){
it.remove();
}
}
用这两个方法才不会出现空指针。
网友评论