Java Array Concatenate concatAll(byte[] a, byte[]... rest)

Here you can find the source of concatAll(byte[] a, byte[]... rest)

Description

concat All

License

Open Source License

Declaration

public static byte[] concatAll(byte[] a, byte[]... rest) 

Method Source Code

//package com.java2s;
/**//from ww  w  .j  a va 2 s. co m
 * Copyright (c) 2010-2018 by the respective copyright holders.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.Arrays;

public class Main {
    public static byte[] concatAll(byte[] a, byte[]... rest) {
        int totalLength = a.length;
        for (byte[] b : rest) {
            totalLength += b.length;
        }

        byte[] result = Arrays.copyOf(a, totalLength);
        int offset = a.length;
        for (byte[] array : rest) {
            System.arraycopy(array, 0, result, offset, array.length);
            offset += array.length;
        }
        return result;
    }
}

Related

  1. concat(T[] head, T... tail)
  2. concat(T[] left, T[] right)
  3. concat(T[] objects)
  4. concat(T[]... arrays)
  5. concat(T[]... tss)
  6. concatAll(byte[] first, byte[]... rest)
  7. concatAll(byte[]... args)
  8. concatAll(T[] first, T[]... rest)
  9. concatAll(T[] first, T[]... rest)