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

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

Description

Concatenate two arrays.

License

Open Source License

Parameter

Parameter Description
first First array
second Second array

Return

Array of length (first.length + second.length) consisting of the elements of first followed by the elements of second .

Declaration

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

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011, 2012 Alex Bradley.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w  w  w  . j av a  2s . c o  m
 *    Alex Bradley - initial API and implementation
 *******************************************************************************/

import java.util.Arrays;

public class Main {
    /**
     * Concatenate two arrays.
     * @param first First array
     * @param second Second array
     * @return Array of length {@code (first.length + second.length)} consisting of the elements of {@code first} 
     * followed by the elements of {@code second}.
     */
    public static <T> T[] arrayConcat(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. arrayConcat(byte[] a, byte[] b)
  2. arrayConcat(final byte[] firstArray, final byte[] secondArray)
  3. arrayConcat(String[] first, String second)
  4. arrayConcat(T[] a, T[] b)
  5. arrayConcat(T[] first, T[] second)
  6. arrayConcatenate(final String[] f, final String[] s)
  7. arrayConcatenate(String[] first, String[] second)
  8. arrayConcatInt(final int[] original, final int[] appender)
  9. concat(boolean[] a, boolean[] b)