package cn.ezhizao.common.utils.collections;

import java.util.Arrays;

/**
 *  数组的工具类
 */
public class ArrayUtils {

    /**
     * 多数组合并
     * @param first
     * @param rest
     * @return
     * @param <T>
     */
    public static <T> T[] concat(T[] first, T[]... rest) {

        int totalLength = first.length;

        for (T[] array : rest) {
            totalLength += array.length;
        }

        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;
    }
}
