Java Array Concatenate concatAll(T[] first, T[]... rest)

Here you can find the source of concatAll(T[] first, T[]... rest)

Description

concat All

License

Open Source License

Declaration

public static <T> T[] concatAll(T[] first, T[]... rest) 

Method Source Code


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

import java.util.Arrays;

public class Main {
    public static <T> T[] concatAll(T[] first, T[]... rest) {
        int totalLength = first.length;
        for (T[] array : rest) {
            totalLength += array.length;
        }//  www .  j  a  v a 2  s  .c om
        T[] result = Arrays.copyOf(first, totalLength);
        int offset = first.length;
        for (T[] array : rest) {
            System.arraycopy(array, 0, result, offset, array.length);
            offset += array.length;
        }
        return result;
    }

    public static double[] concatAll(double[] first, double[]... rest) {
        int totalLength = first.length;
        for (double[] array : rest) {
            totalLength += array.length;
        }
        double[] result = Arrays.copyOf(first, totalLength);
        int offset = first.length;
        for (double[] array : rest) {
            System.arraycopy(array, 0, result, offset, array.length);
            offset += array.length;
        }
        return result;
    }
}

Related

  1. concat(T[]... tss)
  2. concatAll(byte[] a, byte[]... rest)
  3. concatAll(byte[] first, byte[]... rest)
  4. concatAll(byte[]... args)
  5. concatAll(T[] first, T[]... rest)
  6. concatAllArrays(byte[] data1, byte[]... remaining)
  7. concatArray(byte data1[], byte data2[])
  8. concatArray(byte[] old1, byte[] old2)
  9. concatArray(int[] src, String separator)