import java.util.*; public class aaa { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] a = {1,2}; int[] b = {3,4}; int[] c = new int[4]; System.arraycopy(a,0,c,0,2); System.arraycopy(b,0,c,2,2); for(int i=0;i<c.length;i++){ System.out.println(c[i]); } } }
修改一下2楼的 int a[]={1,2}; int b[]={3,4}; 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);
public class aaa { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {1,2};
int[] b = {3,4};
int[] c = new int[4];
System.arraycopy(a,0,c,0,2);
System.arraycopy(b,0,c,2,2);
for(int i=0;i<c.length;i++){
System.out.println(c[i]);
}
}
}
int b[]={3,4};
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);