Java Array Concatenate concat(byte[] a, byte[]... b)

Here you can find the source of concat(byte[] a, byte[]... b)

Description

Returns two byte arrays concatenated.

License

Open Source License

Parameter

Parameter Description
a array 1
b array 2

Return

concatenation of array 1 and 2

Declaration

public static byte[] concat(byte[] a, byte[]... b) 

Method Source Code

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

import java.util.Arrays;

public class Main {
    /**/*from   w  ww .j a  v  a2s .  c  o m*/
     * Returns two byte arrays concatenated.
     *
     * @param a array 1
     * @param b array 2
     * @return concatenation of array 1 and 2
     */
    public static byte[] concat(byte[] a, byte[]... b) {
        int length = a.length;
        for (byte[] bytes : b) {
            length += bytes.length;
        }
        byte[] result = Arrays.copyOf(a, length);
        int pos = a.length;
        for (byte[] bytes : b) {
            System.arraycopy(bytes, 0, result, pos, bytes.length);
            pos += bytes.length;
        }
        return result;
    }
}

Related

  1. arrayConcatenate(final String[] f, final String[] s)
  2. arrayConcatenate(String[] first, String[] second)
  3. arrayConcatInt(final int[] original, final int[] appender)
  4. concat(boolean[] a, boolean[] b)
  5. concat(boolean[]... arys)
  6. concat(byte[] first, byte[] second)
  7. concat(byte[] first, byte[] second)
  8. concat(byte[]... arrays)
  9. concat(double[] first, double[] second)