I\'m looking to move things around within an Array.
I want to be able to move the last item within the given Array to a spot while moving those in the current locati
Another short and quick solution based on System.arraycopy
:
System.arraycopy(array, insert, array, insert+1, array.length-insert-1);
The array content is "pushed to the right" from index "insert".
Here's some demonstration code:
int[] array = {1,2,3,4,5};
int insert = 2;
int last = array[array.length-1];
System.arraycopy(array, insert, array, insert+1, array.length-insert-1);
array[insert] = last;
for (int value:array) System.out.println(value);