Shifting Elements in an Array - Java Language Basics

Java examples for Language Basics:Array

Description

Shifting Elements in an Array

Demo Code


public class Main {
  public void m() {
    int[] array = null;
 // Shift all elements right by one
    System.arraycopy(array, 0, array, 1, array.length-1);

    // Shift all elements left by one
    System.arraycopy(array, 1, array, 0, array.length-1);
  }/*w w w.ja v a 2s .  c  om*/
}

Related Tutorials