Android Array Concatenate concat(byte[] first, byte[]... rest)

Here you can find the source of concat(byte[] first, byte[]... rest)

Description

concat

License

Open Source License

Declaration

public static byte[] concat(byte[] first, byte[]... rest) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Array;

public class Main {
    public static <T> T[] concat(T[] first, T[]... rest) {
        int totalLength = first.length;
        for (T[] arr : rest) {
            totalLength += arr.length;// w  ww. jav a 2s.c om
        }

        T[] result = (T[]) Array.newInstance(first.getClass(), totalLength);
        System.arraycopy(first, 0, result, 0, first.length);
        int pos = first.length;

        for (T[] arr : rest) {
            System.arraycopy(arr, 0, result, pos, arr.length);
            pos += arr.length;
        }

        return result;
    }

    public static byte[] concat(byte[] first, byte[]... rest) {
        int totalLength = first.length;
        for (byte[] arr : rest) {
            totalLength += arr.length;
        }

        byte[] result = new byte[totalLength];
        System.arraycopy(first, 0, result, 0, first.length);
        int pos = first.length;

        for (byte[] arr : rest) {
            System.arraycopy(arr, 0, result, pos, arr.length);
            pos += arr.length;
        }

        return result;
    }
}

Related

  1. concat(T[] first, T[]... rest)
  2. cancat(byte[] a, byte[] b)
  3. arrayApend(byte[] prep, byte after)
  4. arrayComb(byte[] prep, byte[] after)
  5. concat(T[] a, T[] b)