Java Array Concatenate concat(T[] head, T... tail)

Here you can find the source of concat(T[] head, T... tail)

Description

Concatenates two arrays.

License

Open Source License

Parameter

Parameter Description
T the type of elements in the source arrays
head the prefix of the result array
tail the elements to be concatenated to head

Return

the result of concatenating tail to the end of head

Declaration

@SuppressWarnings("unchecked")
public static <T> T[] concat(T[] head, T... tail) 

Method Source Code

//package com.java2s;
/*//from  w w  w.ja va  2s  .c om
 * Copyright (c) 2017, APT Group, School of Computer Science,
 * The University of Manchester. All rights reserved.
 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code 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
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import java.util.*;

public class Main {
    /**
     * Concatenates two arrays.
     *
     * @param <T> the type of elements in the source arrays
     * @param head the prefix of the result array
     * @param tail the elements to be concatenated to {@code head}
     * @return the result of concatenating {@code tail} to the end of {@code head}
     */
    @SuppressWarnings("unchecked")
    public static <T> T[] concat(T[] head, T... tail) {
        T[] result = Arrays.copyOf(head, head.length + tail.length);
        System.arraycopy(tail, 0, result, head.length, tail.length);
        return result;
    }
}

Related

  1. concat(T[] first, T[] second)
  2. concat(T[] first, T[] second)
  3. concat(T[] first, T[] second)
  4. concat(T[] first, T[] second)
  5. concat(T[] first, T[]... rest)
  6. concat(T[] left, T[] right)
  7. concat(T[] objects)
  8. concat(T[]... arrays)
  9. concat(T[]... tss)