I have an array with 8 elements, and I need to remove the first element from it and copy it to the same array. I tried using System.arraycopy (...), but the size of the array has not changed.
int[] array = {90,78,67,56,45,34,32,31};
System.arraycopy(array, 1, array, 0, array.length-1);
what i need is an array should consist of 78,67,56,45,34,32,31 elements with an array size of 7
there is a way to do this by copying it to another array and assigning it to the first array
int arrayB = new int[array.length-1];
System.arraycopy(array, 1, arrayB, 0, array.length-1);
array = arrayB;
but that’s not how I want. I need this to be done without the help of another array.
source
share