且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

合并两个整数数组

更新时间:2022-05-24 22:22:31

不能直接添加,必须新建一个数组,然后将每个数组复制到新的数组中.System.arraycopy 是一种可以用来执行此复制的方法.

You can't add them directly, you have to make a new array and then copy each of the arrays into the new one. System.arraycopy is a method you can use to perform this copy.

int[] array1and2 = new int[array1.length + array2.length];
System.arraycopy(array1, 0, array1and2, 0, array1.length);
System.arraycopy(array2, 0, array1and2, array1.length, array2.length);

无论 array1 和 array2 的大小如何,这都可以工作.

This will work regardless of the size of array1 and array2.