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 byte[] arrayCopy(byte[] old_src, byte[] new_src) {
    byte[] des = new byte[old_src.length + new_src.length];
    System.arraycopy(old_src, 0, des, 0, old_src.length);
    System.arraycopy(new_src, 0, des, old_src.length, new_src.length);
    return des;// w w  w  .ja v  a 2 s.  c o m
}

From source file:Main.java

public static <T> T[] resize(T[] buffer, int newSize, Class<?> componentType) {
    T[] newArray = newArray(componentType, newSize);
    System.arraycopy(buffer, 0, newArray, 0, buffer.length >= newSize ? newSize : buffer.length);
    return newArray;
}

From source file:Main.java

public static int[][] copyArray(int[][] fromArray) {
    int[][] inArray = new int[fromArray.length][fromArray[0].length];
    for (int i = 0; i < fromArray.length; i++)
        System.arraycopy(fromArray[i], 0, inArray[i], 0, fromArray[i].length);

    return inArray;
}

From source file:Main.java

public static MenuElement[] appendPath(MenuElement[] path, MenuElement newElement) {
    MenuElement[] newPath = new MenuElement[path.length + 1];
    System.arraycopy(path, 0, newPath, 0, path.length);
    newPath[newPath.length - 1] = newElement;
    return newPath;
}

From source file:Main.java

public static Object[] increaseSize(int BUFFER, Object[] userObjects, int size) {
    int newSize = userObjects.length + BUFFER;

    Object[] newArray = new Object[newSize];

    System.arraycopy(userObjects, 0, newArray, 0, size);
    userObjects = newArray;/*from  ww  w.  j a  v  a  2  s  . c o  m*/
    return userObjects;
}

From source file:Main.java

public static byte[] copyOfRange(byte[] from, int start, int end) {
    int length = end - start;
    byte[] result = new byte[length];
    System.arraycopy(from, start, result, 0, length);
    return result;
}

From source file:Main.java

public static byte[] truncByteArray(byte[] array, int size) {
    if (size <= array.length) {
        byte[] output = new byte[size];
        System.arraycopy(array, 0, output, 0, size);
        return output;
    }//from w  w  w.j av a 2 s .c  om
    return array;
}

From source file:Main.java

public static byte[] byteMerger(byte[] byte_1, byte[] byte_2) {
    byte[] byte_3 = new byte[byte_1.length + byte_2.length];
    System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
    System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
    return byte_3;
}

From source file:Main.java

public static Object toArray(List<?> list, Class<?> componentType) {
    Object result = Array.newInstance(componentType, list.size());
    System.arraycopy(list.toArray(), 0, result, 0, list.size());
    return result;
}

From source file:Main.java

public static <U> U[] removeIndex(U[] original, Class<U> originalClass, int element) {
    U[] n = (U[]) Array.newInstance(originalClass, original.length - 1);
    System.arraycopy(original, 0, n, 0, element);
    System.arraycopy(original, element + 1, n, element, original.length - element - 1);
    return n;//from  w  ww .j av  a  2s  . c o  m
}