把两个数组合并成一个数组,效率最高的方式是什么啊

解决方案 »

  1.   

    不用排序!只要合并就行了!比如:
    int[] a = {1,2,3,4};int[] b = {3,4,5} ; 合并后int[] c = {1,2,3,4,3,4,5} ;
      

  2.   

    用System.arraycopy方法效率是最高的
    给你个例子:class Test 
    {
    public static void main(String[] args) 
    {
    int[] a = {1,2,3,4};
    int[] b = {3,4,5} ;
    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:c){
    System.out.println(i);
    }
    }
    }
      

  3.   

    是啊,当时笔试时我也写的这个方法!看来用Java复制数组时,这个函数效率应该是最高的,它好像是用了JNI技术