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 <T> T[] arrayConcat(T[] first, T[] second) {
    T[] result = Arrays.copyOf(first, first.length + second.length);
    System.arraycopy(second, 0, result, first.length, second.length);
    return result;
}

From source file:Main.java

public static byte[] concat(byte[] a, byte[] b) {
    int aLen = a.length;
    int bLen = b.length;
    byte[] c = new byte[aLen + bLen];
    System.arraycopy(a, 0, c, 0, aLen);
    System.arraycopy(b, 0, c, aLen, bLen);
    return c;//from ww  w .j  av  a 2  s .c om
}

From source file:Main.java

public static <T> T[] splice(T[] arr, int start, int end) {
    int size = end - start;
    T[] newArr = Arrays.copyOf(arr, size);
    System.arraycopy(arr, start, newArr, 0, size);
    return newArr;
}

From source file:Main.java

public static byte[] sub(byte[] scanRecord, int beginIndex, int endIndex) {
    final int length = endIndex - beginIndex;
    byte[] bytes = new byte[length];
    System.arraycopy(scanRecord, beginIndex, bytes, 0, length);
    return bytes;
}

From source file:Main.java

public static byte[] byteCase(byte[] byte_1, byte[] byte_2, byte[] byte_3) {
    byte[] byteTotal = new byte[byte_1.length + byte_2.length + byte_3.length];

    System.arraycopy(byte_1, 0, byteTotal, 0, byte_1.length);
    System.arraycopy(byte_2, 0, byteTotal, byte_1.length, byte_2.length);
    System.arraycopy(byte_3, 0, byteTotal, byte_1.length + byte_2.length, byte_3.length);

    return byteTotal;
}

From source file:Main.java

public static boolean[] copyOf(boolean[] original, int newLength) {
    boolean[] copy = new boolean[newLength];
    System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
    return copy;//  www . j av  a  2s .  c om
}

From source file:Main.java

public static String getMacAddr(byte[] data) {
    if (data != null && data.length > 11) {
        byte[] macBytes = new byte[6];
        System.arraycopy(data, 5, macBytes, 0, 6);
        return byteToMac(macBytes);
    }//from w w w .  j  a  v  a  2 s  . c o  m
    return null;
}

From source file:Main.java

public static byte[] cutBytes(byte[] bytes, int pos, int length) {
    if (length < 0) {
        return null;
    }//from   www  .j  a v  a 2s.c  o m
    byte[] dest = new byte[length];
    System.arraycopy(bytes, pos, dest, 0, length);
    return dest;
}

From source file:Main.java

public static byte[] encodeData(byte[] headData, byte[] bodyData, byte[] footData) {
    byte[] data = new byte[headData.length + bodyData.length + footData.length];
    System.arraycopy(headData, 0, data, 0, headData.length);
    System.arraycopy(bodyData, 0, data, headData.length, bodyData.length);
    System.arraycopy(footData, 0, data, headData.length + bodyData.length, footData.length);
    return data;/*  ww  w.jav  a  2s.  c  om*/
}

From source file:Main.java

public static String[] concatStringArrays(String[] A, String[] B) {
    int aLen = A.length;
    int bLen = B.length;
    String[] C = new String[aLen + bLen];
    System.arraycopy(A, 0, C, 0, aLen);
    System.arraycopy(B, 0, C, aLen, bLen);
    return C;/*from ww w.j a  v a 2 s .co m*/
}