Loading

System.arraycopy方法

//native方法,将src的数组从索引从srcPos开始,长度为length,复制到dest数组,索引为destPos,长度为length
public static native void arraycopy(Object src,  int  srcPos,
                                        Object dest, int destPos,
                                        int length);

 

 

@Test
    void contextLoads() {
        String[] arr1 = {"a1","a2","a3","a4","a5"};
        String[] arr2 = {"b1","b2","b3","b4","b5"};
        System.arraycopy(arr1,1,arr2,1,3);
        for (String s : arr2) {
            System.out.println(s);
        }
        System.out.println("=======================");
        String[] arr3 = {"a1","a2","a3","a4","a5"};
        String[] arr4 = new String[5];
        System.arraycopy(arr3,1,arr4,1,3);
        for (String s : arr4) {
            System.out.println(s);
        }
    }

 运行结果:

 

posted @ 2020-04-13 09:48  秋风飒飒吹  阅读(266)  评论(0编辑  收藏  举报