Generic method to concatenate All arrays and return a big array - Android java.lang

Android examples for java.lang:Array Element

Description

Generic method to concatenate All arrays and return a big array

Demo Code


//package com.java2s;
import java.util.Arrays;

public class Main {
    public static <T> T[] concatAll(T[] first, T[]... rest) {
        int totalLength = first.length;
        for (T[] array : rest) {
            totalLength += array.length;
        }/*from w  w w.j  av  a 2s  .  co m*/
        T[] result = Arrays.copyOf(first, totalLength);
        int offset = first.length;
        for (T[] array : rest) {
            System.arraycopy(array, 0, result, offset, array.length);
            offset += array.length;
        }
        return result;
    }
}

Related Tutorials