现在已知数组
int a[]={1,2};
int b[]={3,4};
怎样占用较少资源实现将b的元素加到a的末位生成新的数组?能不遍历数组最好了
先谢过了

解决方案 »

  1.   

    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.   

    修改一下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);