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

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

Description

Concatenate two arrays of the same type.

License

Open Source License

Parameter

Parameter Description
first the first array
second the second array

Return

a new array containing the elements of the first and second arrays in order

Declaration

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

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2012 Constantine Lignos
 * //from   w  w w .j  a v a2  s.  c  om
 * This file is a part of MORSEL.
 * 
 * MORSEL is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * MORSEL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MORSEL.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

import java.util.Arrays;

public class Main {
    /**
     * Concatenate two arrays of the same type.
     * @param first the first array
     * @param second the second array
     * @return a new array containing the elements of the first and second arrays in order
     */
    public static <T> T[] concatArrays(T[] first, T[] second) {
        T[] result = Arrays.copyOf(first, first.length + second.length);
        System.arraycopy(second, 0, result, first.length, second.length);
        return result;
    }
}

Related

  1. concatArrays(final char[] first, final char[]... rest)
  2. concatArrays(Object[] ar1, Object[] ar2)
  3. concatArrays(short[] arr1, short[] arr2)
  4. concatArrays(String[] A, String[] B)
  5. concatArrays(String[] array, String[] arrayToBeConcat)
  6. concatArrays(T[] first, T[] second)
  7. concatByteArrays(final byte[] array1, final byte[] array2)
  8. concatenate(@SuppressWarnings("unchecked") T[]... arrays)
  9. concatenate(byte[] a, byte[] b)