Java Array Concatenate concat(final T[] first, final T[] second)

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

Description

Merges two arrays together

License

Open Source License

Parameter

Parameter Description
first The first source array
second The second source array

Return

An array that combines the two arrays

Declaration

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

Method Source Code


//package com.java2s;

import java.util.Arrays;

public class Main {
    /**//  www . ja va  2s .c  om
     * Merges two arrays together
     *
     * @param first  The first source array
     * @param second The second source array
     * @return An array that combines the two arrays
     */
    public static <T> T[] concat(final T[] first, final T[] second) {
        /* deal with null inputs */
        if (first == null && second == null)
            return null;
        if (first == null)
            return second;
        if (second == null)
            return first;

        final T[] result = Arrays.copyOf(first, first.length + second.length);
        System.arraycopy(second, 0, result, first.length, second.length);
        return result;
    }
}

Related

  1. concat(byte[] first, byte[] second)
  2. concat(byte[] first, byte[] second)
  3. concat(byte[]... arrays)
  4. concat(double[] first, double[] second)
  5. concat(final T[] elements, final T... elementsToAppend)
  6. concat(float[] A, float[] B)
  7. concat(int[] first, int[] second)
  8. concat(int[]... arrays)
  9. concat(Object[] array)