shift elements of array java code example
Example: shift elements in array java
// Shift right from index of 'a' to 'b'
for(int i = b; i>a; i--) { array[i] = array[i-1]; }
/* Note: element at 'a' index will remain unchanged */
// Shift left from index of 'b' to 'a'
for(int i = a; i<b; i++) { array[i] = array[i+1]; }
/* Note: element at 'b' index will remain unchanged */