Here is the method I wrote for my Java programming class
private static double[] extendArraySize(double [] array){ double [] temp = array.clone(); array = new double[array.length + 1]; System.arraycopy(temp, 0, array, 0, temp.length); return array; }
This is a fairly independent explanation of how this works, although along the path that he used it should have an array assigned to the method with the name of the array passed as an argument, and the data type of the method should always be the type of the passed array.
Example:
double [] z = {1,2,3}; //size of z = 3; [0,1,2] VALUES: [1,2,3] z = extendArraySize(z); //size of z = 4; [0,1,2,3] VALUES: [1,2,3,0];
Sorry if he explained horribly, and I'm sure there is a better way to do this with VIA vectors or ArrayLists. But if you want to expand a primitive array, this is one way to do this.
I hope I helped = D
Nick
source share