Java Array Merge merge(T[] left, T... right)

Here you can find the source of merge(T[] left, T... right)

Description

merge

License

Open Source License

Parameter

Parameter Description
T The array element type.
left Array to be merged.
right Varargs to be merged with array.

Return

A new array with first all the elements of @left, then all the vararg elements of @right.

Declaration

public static <T> T[] merge(T[] left, T... right) 

Method Source Code

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

import java.util.Arrays;

public class Main {
    /**/*from  w  w  w . j a  v a 2  s  . co m*/
     *
     * @param <T>   The array element type.
     * @param left  Array to be merged.
     * @param right Varargs to be merged with array.
     *
     * @return A new array with first all the elements of @left, then all the vararg elements of @right.
     */
    public static <T> T[] merge(T[] left, T... right) {
        int newLength = left.length + right.length;
        T[] newArray = Arrays.copyOf(left, newLength);
        for (int i = left.length; i < newLength; i++) {
            newArray[i] = right[i - left.length];
        }
        return newArray;
    }
}

Related

  1. merge(String[]... arrays)
  2. merge(T[] array, T[] temp, int left, int middle, int right)
  3. merge(T[] array1, T[] array2)
  4. merge(T[] first, T[] second)
  5. merge(T[] first, T[] second)
  6. merge(T[]... arrays)
  7. merge(T[]... many)
  8. merge2TablesWithoutDup(String[] t1, String[] t2)
  9. mergeAndOrderArray(int[] arrA, int[] arrB)