Here you can find the source of concat(T[]... arrays)
Parameter | Description |
---|---|
arrays | The arrays being concatenated |
@SafeVarargs public static <T> T[] concat(T[]... arrays)
//package com.java2s; /*/* www. j a va 2 s . c om*/ * Copyright 2018 ImpactDevelopment * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.*; public class Main { /** * Concatenates an array of generic arrays * * @param arrays The arrays being concatenated * @return The concatenated array */ @SafeVarargs public static <T> T[] concat(T[]... arrays) { if (arrays.length < 2) throw new IllegalArgumentException("At least 2 arrays should be supplied"); T[] result = arrays[0]; for (int i = 1; i < arrays.length; i++) { T[] newArray = Arrays.copyOf(result, result.length + arrays[i].length); System.arraycopy(arrays[i], 0, newArray, result.length, arrays[i].length); result = newArray; } return result; } }