Here you can find the source of mergeArrays(byte[] first, byte[]... more)
Parameter | Description |
---|---|
first | The first array to be placed into the new array. |
more | More byte arrays to merge. |
public static byte[] mergeArrays(byte[] first, byte[]... more)
//package com.java2s; // See LICENSE.txt for license information import java.util.Arrays; public class Main { /**//from w w w. j a va2s .co m * Merges two or more byte arrays into one. * @param first The first array to be placed into the new array. * @param more More byte arrays to merge. * @return A new byte array containing the data of every specified array. */ public static byte[] mergeArrays(byte[] first, byte[]... more) { int totalLength = first.length; for (byte[] ar : more) { totalLength += ar.length; } byte[] res = Arrays.copyOf(first, totalLength); int offset = first.length; for (byte[] ar : more) { System.arraycopy(ar, 0, res, offset, ar.length); offset += ar.length; } return res; } /** * Merges two or more generic arrays of the same type into one. * Note: The result for arrays of different types but common base type is undefined. * @param first The first array to be placed into the new array. * @param more More arrays of the same type to merge. * @return A new array containing the data of all specified arrays. */ public static <T> T[] mergeArrays(T[] first, T[]... more) { int totalLength = first.length; for (T[] ar : more) { totalLength += ar.length; } T[] res = Arrays.copyOf(first, totalLength); int offset = first.length; for (T[] ar : more) { System.arraycopy(ar, 0, res, offset, ar.length); offset += ar.length; } return res; } }