Here you can find the source of concatAll(final T[] empty, Iterable
Parameter | Description |
---|---|
empty | An empty array of the right type used for cloning |
arrayList | A list of arrays to concatenate. |
public static <T> T[] concatAll(final T[] empty, Iterable<T[]> arrayList)
//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; } }