Java Array Concatenate arrayConcat(T[] first, T[] second)

Here you can find the source of arrayConcat(T[] first, T[] second)

Description

Concatenate two arrays of type T and produce a new of the same type.

License

Open Source License

Parameter

Parameter Description
T a parameter
first An array of type T with arbitrary length
second An array of type T with arbitrary length

Return

An array of T, resulted from the concatenation of the given two arrays

Declaration

public static <T> T[] arrayConcat(T[] first, T[] second) 

Method Source Code

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

import java.util.Arrays;

public class Main {
    /**//from   w  w w. j av a  2  s. c  om
     * Concatenate two arrays of type T and produce a new of the same type. The first array is
     * inserted first followed by the second.
     * 
     * @param <T>
     * @param first
     *            An array of type T with arbitrary length
     * @param second
     *            An array of type T with arbitrary length
     * @return An array of T, resulted from the concatenation of the given two arrays
     */
    public static <T> T[] arrayConcat(T[] first, T[] second) {
        T[] combinedArray = Arrays.copyOf(first, first.length
                + second.length);
        System.arraycopy(second, 0, combinedArray, first.length,
                second.length);
        return combinedArray;
    }
}

Related

  1. arraycat(String[][] array1, String[][] array2)
  2. arrayConcat(byte[] a, byte[] b)
  3. arrayConcat(final byte[] firstArray, final byte[] secondArray)
  4. arrayConcat(String[] first, String second)
  5. arrayConcat(T[] a, T[] b)
  6. arrayConcat(T[] first, T[] second)
  7. arrayConcatenate(final String[] f, final String[] s)
  8. arrayConcatenate(String[] first, String[] second)
  9. arrayConcatInt(final int[] original, final int[] appender)