Java List Concatenate concatAll(final T[] empty, Iterable arrayList)

Here you can find the source of concatAll(final T[] empty, Iterable arrayList)

Description

Concatenate an list of arrays of typed-objects

License

Open Source License

Parameter

Parameter Description
empty An empty array of the right type used for cloning
arrayList A list of arrays to concatenate.

Return

The concatenated mega-array.

Declaration

public static <T> T[] concatAll(final T[] empty, Iterable<T[]> arrayList) 

Method Source Code

//package com.java2s;
/* This file is part of VoltDB.
 * Copyright (C) 2008-2015 VoltDB Inc./*from   w w w .j a  v  a 2  s.  c o  m*/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with VoltDB.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Arrays;

public class Main {
    /**
     * Concatenate an list of arrays of typed-objects
     * @param empty An empty array of the right type used for cloning
     * @param arrayList A list of arrays to concatenate.
     * @return The concatenated mega-array.
     */
    public static <T> T[] concatAll(final T[] empty, Iterable<T[]> arrayList) {
        assert (empty.length == 0);
        if (arrayList.iterator().hasNext() == false) {
            return empty;
        }

        int len = 0;
        for (T[] subArray : arrayList) {
            len += subArray.length;
        }
        int pos = 0;
        T[] result = Arrays.copyOf(empty, len);
        for (T[] subArray : arrayList) {
            System.arraycopy(subArray, 0, result, pos, subArray.length);
            pos += subArray.length;
        }
        return result;
    }
}

Related

  1. concat(List a, List b)
  2. concat(List collection1, List collection2)
  3. concat(List l1, List l2)
  4. concat(List list, T... items)
  5. concatAddresses(List addresses)
  6. concatArrays(List arrays, int start, int size)
  7. concatArraysToList(final T[]... arrays)
  8. concatCsvLine(List values, String fieldSeparator)
  9. concateAliases(List aliases)