Java Array Merge merge(T[] array1, T[] array2)

Here you can find the source of merge(T[] array1, T[] array2)

Description

Merge two array in a single one.

License

Open Source License

Parameter

Parameter Description
T the generic type
array1 the first array
array2 the second array

Return

an array containing all elements from array1 and array2 (the first element is the first element of array1 )

Declaration

public static <T> T[] merge(T[] array1, T[] array2) 

Method Source Code

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

import java.util.Arrays;

public class Main {
    /**/*from  www .  j a va2s  . c  om*/
     * Merge two array in a single one.
     * 
     * @param <T>
     *            the generic type
     * @param array1
     *            the first array
     * @param array2
     *            the second array
     * @return an array containing all elements from {@code  array1} and {@code  array2} (the first element is the first
     *         element of {@code  array1})
     */
    public static <T> T[] merge(T[] array1, T[] array2) {
        T[] merge = Arrays.copyOf(array1, array1.length + array2.length);
        for (int i = 0; i < array2.length; i++) {
            merge[i + array1.length] = array2[i];
        }
        return merge;
    }
}

Related

  1. merge(String[] array1, String[] array2)
  2. merge(String[] strArr1, String[] strArr2)
  3. merge(String[] strArray)
  4. merge(String[]... arrays)
  5. merge(T[] array, T[] temp, int left, int middle, int right)
  6. merge(T[] first, T[] second)
  7. merge(T[] first, T[] second)
  8. merge(T[] left, T... right)
  9. merge(T[]... arrays)