I am trying to add a value to the end of an array. I got this to work for arrays that have a fixed length, but now I need to make it work for arrays of any size. I think a simple for loop would do the trick, I just cannot figure out the syntax.
double[] array2 = new double[array.length + 1];
System.arraycopy(array, 0, array2, 0, array.length);
array2[array.length] = val;
array = array2;
return array2;