我正在研究以下问题:
编写一个方法 removeAll ,它接受一个整数值作为参数,并从列表中删除所有出现的给定值。
我的代码没有检查数组中的所有元素。当我将 for 循环中的“大小”更改为数组中的整数数时,它工作正常。它检查所有这些。
public class ArrayIntList { 
    private int[] elementData;
    private int size;
}
public void remove(int index) {
    for(int i = index; i < size-1; i++) {
        elementData[i] = elementData[i+1];
    }
    size--;
}
public void removeAll(int num) {
    for (int j = 0; j < size; j++) {// this loop doesn't check all the elements
        if (elementData[j] == num) {
            remove(j);
        } 
    }
}