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[] cropByteArray(byte[] target, int offset, int length) {
    byte[] result = new byte[length];
    System.arraycopy(target, offset, result, 0, (length));
    return result;
}

From source file:Main.java

public static byte[] addBytes(byte[] src1, byte[] src2) {
    byte[] dest = new byte[src1.length + src2.length];
    System.arraycopy(src1, 0, dest, 0, src1.length);
    System.arraycopy(src2, 0, dest, src1.length, src2.length);
    return dest;/*from w w  w .j  av  a2  s  . co m*/
}

From source file:Main.java

public static byte[] convertStringToBytes(String str) {
    byte[] bytes = new byte[str.length() * Character.SIZE];
    System.arraycopy(str.toCharArray(), 0, bytes, 0, bytes.length);
    return bytes;
}

From source file:Main.java

private static byte[] extractBytes(byte[] scanRecord, int start, int length) {
    byte[] bytes = new byte[length];
    System.arraycopy(scanRecord, start, bytes, 0, length);
    return bytes;
}

From source file:Main.java

public static String convertByteToString(byte[] bytes) {
    char[] chars = new char[bytes.length / Character.SIZE];
    System.arraycopy(bytes, 0, chars, 0, bytes.length);
    return new String(chars);
}

From source file:Main.java

public static int[] merge(int[] array1, int[] array2) {
    int[] dest = new int[array1.length + array2.length];
    System.arraycopy(array1, 0, dest, 0, array1.length);
    System.arraycopy(array2, 0, dest, array1.length, array2.length);
    return dest;/*  w w  w.  j  av  a 2s  .  c o m*/
}

From source file:Main.java

public static byte[] concatenateByteArrays(byte[] a, byte[] b) {
    byte[] result = new byte[a.length + b.length];
    System.arraycopy(a, 0, result, 0, a.length);
    System.arraycopy(b, 0, result, a.length, b.length);
    return result;
}

From source file:Main.java

public static String[] changeArray(String[] src, int index) {
    String[] dest = new String[src.length - 1];
    System.arraycopy(src, 0, dest, 0, index);
    System.arraycopy(src, index + 1, dest, index, dest.length - index);
    return dest;//from ww w  . j a  v  a2s  .c o  m
}

From source file:Main.java

public static byte[] concatByteArray(byte[] a, byte[] b) {
    byte target[] = new byte[(short) (a.length + b.length)];
    System.arraycopy(a, 0, target, 0, a.length);
    System.arraycopy(b, 0, target, a.length, b.length);
    return target;
}

From source file:Main.java

public static void copy(final byte[] src, final int srcPos, final byte[] dst, final int dstPos,
        final int length) {
    System.arraycopy(src, srcPos, dst, dstPos, length); // Burn in hell, creators of methods that take Object where they shouldn't!
}