直接看代码:

package org.cs.test;
import java.util.Arrays;
public class ArrayCopy {
                       
    public static String[] concat(String[] first, String[] seond) {
        String[] result= new String[first.length + second.length];
        System.arraycopy(first, 0, result, 0, first.length);
        System.arraycopy(second, 0, result, first.length, second.length);
        return result;
    }
                       
                       
    public static  T[] concat(T[] first, T[] second) {
        T[] result = Arrays.copyOf(first, first.length + second.length);
        System.arraycopy(second, 0, result, first.length, second.length);
        return result;
    } 
                       
    public static  T[] concatAll(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;
    }
                       
    public static void main(String[] args) {
        String []a = {"a", "aa"};
        String []b = {"b", "bb"};
        String []c = {"c", "cc"};
        String []arr1 = concat(a, b);
        for (String string : arr1) {
            System.out.println(string);
        }
        System.out.println("=============");
        String []arr2 = concat(a, b);
        for (String string : arr2) {
            System.out.println(string);
        }
        System.out.println("=============");
        String []arr3 = concatAll(a, b, c);
        for (String string : arr3) {
            System.out.println(string);
        }
    }
}


输出结果:

a

aa

b

bb

=============

a

aa

b

bb

=============

a

aa

b

bb

c

cc