I have some java code here and I am creating an ADT for ArrayList (I know Java framework has one, but I just want to see what is underneath it). Here, I'm creating an a method that doubles the size of the array.
My question is, when I do oldArray=newArray, what happens in memory. My guess is that the variable pointing at the oldArray now points at the new array. But now, in memory, does that mean there are 2 variables pointing at the new array? And since there is no reference to the old array, will the garbage collector remove the old array from memory?
public void resize(int newCapacity) {
E[] newData = (E[]) new Object[2*data.length];
for(int i=0; i<data.length; i++) {
newData[i] = data[i];
}
data = newData;
}
newCapacity) that we can compile & run?