在定义一个数组c,将a,b的值赋给c

静态定义两个数组
int[ ] a={11,22,33,44,55};
int b[ ]={12,45,78,65};
在定义一个数组c,将a,b的值赋给c


public class t7 {
    public static void main(String[] args) {
        int[] a={11,22,33,44,55};
        int[] b={12,45,78,65};

        int[] c=new int[a.length+b.length];
        System.arraycopy(a, 0, c, 0, a.length);
        System.arraycopy(b, 0, c, a.length, b.length);
        for (int i = 0; i < c.length; i++) {
            System.out.println(c[i]);
        }
    }
}

参考
https://blog.csdn.net/jaycee110905/article/details/9179227
如有帮助,请采纳


public static void main(String[] args) throws Exception {

        int[] a={11,22,33,44,55};
        int b[]={12,45,78,65};
        int [] c= new int[a.length+b.length];
        System.arraycopy(a, 0, c, 0, a.length);
        System.arraycopy(b, 0, c, a.length, b.length);
        System.out.println("c的内容:"+Arrays.toString(c));
    }
int[] a = {11, 22, 33, 44, 55};
int[] b = {12, 45, 78, 65};
int[] c = new int[a.length + b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);

1、声明三个数组

        int[] a = {11, 22, 33, 44, 55};
        int[] b = {12, 45, 78, 65};
//因为把数组a和数组b的值全部赋给c,所以数组c的长度就是a、b俩数组长度的总和
        int[] c = new int[a.length + b.length];

2、先把数组a copy到c中

 System.arraycopy(a, 0, c, 0, a.length);

arraycopy是系统自带的方法,把a数组从下标为0开始复制到c数组,也从下标为0开始,复制a数组长度个
3、再把数组b copy到c中

 System.arraycopy(b, 0, c, a.length, b.length);

这个时候就要注意了,因为现在数组c中已经a数组长度个元素了,所以往c数组中复制元素的话就得从a数组长度为下标这个位置开始
4、打印一波

  System.out.println(Arrays.toString(c));
[11, 22, 33, 44, 55, 12, 45, 78, 65]

介么索勒,你这个直接看看这俩有多大,然后创一个这俩大小和的数组,再遍历这俩一个一个丢进去呗