Java Array Merge merge(T[]... arrays)

Here you can find the source of merge(T[]... arrays)

Description

Merges a set of arrays into a single list, maintaining original order

License

Open Source License

Parameter

Parameter Description
arrays set of arrays to combine into a list
T type of object included in the set of arrays

Return

a combined list including all original objects in the given arrays

Declaration

public static <T> List<T> merge(T[]... arrays) 

Method Source Code


//package com.java2s;
/*// ww w.j ava 2  s. co m
 * This file is part of Commodus.
 *
 * Commodus 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.
 *
 * Commodus 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 Commodus.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.*;

public class Main {
    /**
     * Merges a set of arrays into a single list, maintaining original order
     *
     * @param arrays set of arrays to combine into a list
     * @param <T>    type of object included in the set of arrays
     * @return a combined list including all original objects in the given arrays
     */
    public static <T> List<T> merge(T[]... arrays) {
        ArrayList<T> merged = new ArrayList<>();
        for (T[] array : arrays) {
            Collections.addAll(merged, array);
        }
        return merged;
    }
}

Related

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