public void add(int index, int element) {
if (this.size == this.capacity) grow();
if (index < size) System.arraycopy(this.array, index, this.array, index + 1, this.size - index);
this.array[index] = element; this.size++;
}
private void grow() {
this.capacity += this.capacity >> 1;
int[] newArray = new int[this.capacity];
System.arraycopy(this.array, 0, newArray, 0, this.size);
this.array = newArray;
}
public int remove(int index) {
int removed = this.array[index];
System.arraycopy(this.array, index + 1, this.array, index, this.size - index - 1);
this.size--;
return removed;
}