Shift all elements in array right by one in Java
Description
The following code shows how to shift all elements right by one.
Example
//from w w w . ja va 2s . co m
import java.util.Arrays;
public class Main {
public static void main(String[] argv) throws Exception {
int[] array = { 1, 2, 3,4,5,6,7,8,9,0 };
System.arraycopy(array, 0, array, 1, array.length - 1);
System.out.println(Arrays.toString(array));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »