You cannot increase the size of the original array. But you can create a new array, copy both the original arrays into it, and assign a reference variable to it.
For example, here is an example of a simple implementation. (An alternative is to use System.arraycopy() .)
float[] newerArray = new float[ newarray.length + arraytobecopied.length ]; for ( int i = 0; i < newarray.length; ++i ) { newerArray[i] = newarray[i]; } for ( int i = 0; i < arraytobecopied.length; ++i ) { newerArray[ newarray.length + i ] = arraytobecopied[i]; } newarray = newerArray;
Alternatively, you can use java.util.ArrayList , which automatically processes the extension of the internal array. Its toArray() methods make it easy to convert a list to an array when required.
source share