resize array in java 1

resize array in java

int [] basedata = new int[10];

int [] original = basedata;
basedata = new int[12];

for(int i = 0; i < original.length; i++){
  basedata[i] = original[i];
}

Here is what the above code is Doing:
1. Create an array of 10 integers called basedata.
2. Create a second array called original that points to the same array as basedata.
3. Create a new array of 12 integers called basedata.
4. Copy the values from the original array into the new array.

Similar Posts