Example usage for java.lang System arraycopy

List of usage examples for java.lang System arraycopy

Introduction

In this page you can find the example usage for java.lang System arraycopy.

Prototype

@HotSpotIntrinsicCandidate
public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length);

Source Link

Document

Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int[] array = { 1, 2, 3 };
    System.arraycopy(array, 1, array, 0, array.length - 1);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int[] array = { 1, 2, 3 };

    System.arraycopy(array, 0, array, 1, array.length - 1);
    System.out.println(Arrays.toString(array));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int[] src = { 1, 2, 3 };
    int[] dst = { 1, 1, 1 };
    System.arraycopy(src, 0, dst, 0, Math.min(src.length, dst.length));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int[] array = { 1, 2, 3 };

    System.arraycopy(array, 0, array, 1, array.length - 1);
    System.out.println(Arrays.toString(array));

    array = new int[] { 1, 2, 3 };
    System.arraycopy(array, 1, array, 0, array.length - 1);
    System.out.println(Arrays.toString(array));
}

From source file:MainClass.java

public static void main(String[] a) {
    int[] array1 = { 1, 2, 3, 4 };
    int[] array2 = new int[array1.length];
    System.arraycopy(array1, 0, array2, 0, array1.length);

    for (int i : array2) {

        System.out.println(i);//from  w ww . j  a v a2 s  .  c  o m
    }
}

From source file:Main.java

public static void main(String[] args) {
    String[] letters = { "A", "I", "U", "E", "O" };

    String[] results = new String[3];

    System.arraycopy(letters, 2, results, 0, 3);

    for (int i = 0; i < results.length; i++) {
        System.out.println("result = " + results[i]);
    }/*from  www  .jav a 2s . c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    int[] intArray = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };

    int[] arrayCopy = new int[intArray.length];

    System.arraycopy(intArray, 0, arrayCopy, 0, intArray.length);

    for (int i = 0; i < arrayCopy.length; i++)
        System.out.println(arrayCopy[i]);
}

From source file:Main.java

public static void main(String[] args) {

    int arr1[] = { 0, 1, 2, 3, 4, 5 };
    int arr2[] = { 0, 10, 20, 30, 40, 50 };

    // copies an array from the specified source array
    System.arraycopy(arr1, 0, arr2, 0, 1);
    System.out.print("array2 = ");
    System.out.print(arr2[0] + " ");
    System.out.print(arr2[1] + " ");
    System.out.print(arr2[2] + " ");
    System.out.print(arr2[3] + " ");
    System.out.print(arr2[4] + " ");
}

From source file:Main.java

public static void main(String[] args) {
    String[] names = new String[] { "A", "B", "C" };

    String[] extended = new String[5];

    extended[3] = "D";
    extended[4] = "F";

    System.arraycopy(names, 0, extended, 0, names.length);

    for (String str : extended)
        System.out.println(str);//from   w  ww.j a  v a2s .  c o  m
}

From source file:Main.java

public static void main(String[] args) {
    int[] data = { 1, 2, 3, 4, 5 };

    // Copy data array to new arrays 
    int[] eData = new int[9];
    int[] tData = new int[2];
    System.arraycopy(data, 0, eData, 0, 5);
    System.arraycopy(data, 0, tData, 0, 2);

    System.out.println("Original  Array: " + Arrays.toString(data));
    System.out.println("Expanded Array: " + Arrays.toString(eData));
    System.out.println("Truncated  Array: " + Arrays.toString(tData));
}