Java array replication method for copying arrays in java
1. for Loop replication, but the efficiency is low
2. Reference, let the two arrays point to the same memory, but the isolation is poor, it is easy to change the value without knowing
3. Call the java method:
A. System. arraycopy (a1, 0, a2, 0, length)
A1 and a2 are two arrays. The first 0 indicates the starting point of a1, the second indicates the starting point of a2, and The length indicates the length to be copied.
B. a2 = Arrays. copyOf (a1, a. length)
Create an array copy
There are several methods for copying arrays in java.
The simplest one is to directly assign the value of the original array to the new array, but System is generally used. arraycopy (the number of the original array's start copy, the starting number of the new array's reception copy, and the value length)
There are several methods for copying arrays in java.
The simplest one is to directly assign the value of the original array to the new array, but System is generally used. arraycopy (the number of the original array's start copy, the starting number of the new array's reception copy, and the value length)