集册 Java实例教程 合并两个数组的内容并返回结果。

合并两个数组的内容并返回结果。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

375
合并两个数组的内容并返回结果。

/**
来 自 时代Java公众号 - N o w J a  v a . c o m
**/

//package com.nowjava;

import java.lang.reflect.Array;


public class Main {

    /**

     * Combine the contents of two arrays and return the result. Array B will be appended onto array A

     * @param a The first array

     * @param b The second array

     * @param <T> The types of these arrays

     * @return An array with the contents of both A and B

     */

    public static <T> T[] combine(T[] a, T[] b) {

        int aLen = a.length;

        int bLen = b.length;


        @SuppressWarnings("unchecked")

        T[] c = (T[]) Array.newInstance(a.getClass().getComponentType(),

                aLen + bLen);

        
展开阅读全文