[Java] assigns the same value to all elements of the array and copies between arrays.
Assign the same value to all elements of the array:
boolean[] resArray=new boolean[100]; Arrays.fill(resArray, true);
Copying between Arrays:
System.arraycopy(Object src, int srcPos, Object dst, int dstPos, int length)
Src: source array; srcPos: Start position of the source array to be copied; dest: Destination array; destPos: Start position of the destination array; length: Copy length.
Note: Both src and dest must be of the same type or an array that can be converted. Interestingly, this function can be used to copy data on its own,
For example: int [] fun = {0, 1, 2, 3, 4, 5, 6}; System. arraycopy (fun, 0, fun, 3, 3); the result is: {, 6 };
JAVA programming array replication, assigning the first five elements of array a1 to b1
Public class SetArray {
Public static void main (String [] args ){
Int [] a = {1, 2, 3, 4, 5, 6, 7 };
Int [] B = {1, 1, 8, 9, 10, 11, 12 };
For (int I = 0; I <5; I ++ ){
B [I] = a [I];
System. out. println (B [I]);
}
}
}
How does Java attach elements of a string array to another string array?
ArrayCopy ();
Public static void arraycopy (Object src,
Int srcPos,
Object dest,
Int destPos,
Int length): copy an array from the specified source array. Copy starts from the specified position and ends at the specified position of the target array. From the source array referenced by src to the target array referenced by dest, A subsequence of the array component is copied. The number of the copied component is equal to the length parameter. Components located between srcPos and srcPos + length-1 in the source array are copied to destPos and destPos + length-1 in the target array respectively.
CopyOf () and copyOfRange () of java. util. Arrays class ();
Public staic xxx [] copyOf (xxx [] original.int newLength)
Original is an array reference of any type. It refers to the source array. newLength is the length of the test bay.
Public static xxx [] copyOfRange (xxx [] original, int from, int)
Original is an array reference of any type. It refers to the source array, from test bay to-1.