No, that is not a valid way to do it. What you are doing is actually
First create a new larger array
Throw away the newly created array and copy the original array
Create year another new array with larger size
Throw away the newly created array and clone the already cloned array again
For non primitive types I think you want to use the ArrayList
However, if you want to build this for primitive types, this is how you would do it
public int size = 0;
public int[] origArray = new int[size+1];
public void expand(){
int[] tempArray = new int[size+1];
System.arrayCopy(origArray, 0, tempArray, 0, size);
origArray = tempArray;
size++;
}
You probably want to hide the data behind accessors (get...() methods) and you do not want to just expand the array by one element at a time, creating and copying arrays is costly.