java 数组合并 A,B,C 3个数组,要合在一起成为一个新的数组,有什么办法么
展开全部
应该是三个合成一个新的,都是一维的,对吧。
public class Test {
public static void main(String[] args) {
System.out.println("Hello World! 中国人人在");
int[] a = new int[]{1,2,3};
int[] b = new int[]{4,5,6};
int[] c = new int[]{7,8,9};
int[] d = new int[a.length + b.length + c.length];
System.arraycopy(a,0,d,0,a.length);
// System.arraycopy(b,0,d,3,b.length);
// System.arraycopy(c,0,d,6,c.length);
System.arraycopy(b,0,d,a.length,b.length);
System.arraycopy(c,0,d,a.length + b.length,c.length);
System.out.println(d.length);
for(int i : d){
System.out.println(i);
}
}
}
public class Test {
public static void main(String[] args) {
System.out.println("Hello World! 中国人人在");
int[] a = new int[]{1,2,3};
int[] b = new int[]{4,5,6};
int[] c = new int[]{7,8,9};
int[] d = new int[a.length + b.length + c.length];
System.arraycopy(a,0,d,0,a.length);
// System.arraycopy(b,0,d,3,b.length);
// System.arraycopy(c,0,d,6,c.length);
System.arraycopy(b,0,d,a.length,b.length);
System.arraycopy(c,0,d,a.length + b.length,c.length);
System.out.println(d.length);
for(int i : d){
System.out.println(i);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询