System.arraycopy() method

 public static void main(String[] args) {
        int[] ints1 = {3, 4, 5, 6, 7, 8};
        int[] ints2 = new int[6];

        String ints1Str = "";
        for (int i : ints1) {
            ints1Str += i;
            ints1Str += ",";
        }
        System.out.println(ints1Str);
         /**
         * Object src:the source array. 源数组
         * int srcPos:starting position in the source array. 在源数组中,开始复制的位置
         * Object dest:the destination array. 目标数组
         * int destPos:starting position in the destination data. 在目标数组中,开始赋值的位置
         * int length:the number of array elements to be copied. 被复制的数组元素的数量
         */
        System.arraycopy(ints1, 0, ints2, 0, ints1.length);

        String ints2Str = "";
        for (int i : ints2) {
            ints2Str += i;
            ints2Str += ",";
        }
        System.out.println(ints2Str);
    }

 

Guess you like

Origin blog.csdn.net/qq_42407917/article/details/109174503