API provides a lot of methods for program developers to use, the next two will share with you two common array operation methods, today to introduce the first method- the copy operation of the array .
Example: Testjava4_4.java
01//The following procedure describes the copy operation of the array
public class Testjava4_4
03 {
public static void Main (string[] args)
05 {
a1[int] = {1,2,3,4,5}; Declares two integer arrays A1, A2, and initializes them statically
-int a2[] = {9,8,7,6,5,4,3};
System.arraycopy (a1,0,a2,0,3); Operations that perform array copies
System.out.print ("contents of the A1 array:");
Ten for (int i=0;i<a1.length;i++)//output A1 The contents of the array
One System.out.print (a1[i]+ "");
System.out.println ();
13
System.out.print ("contents of the A2 array:");
(int i=0;i<a2.length;i++)//Output a2 the contents of the array
System.out.print (A2[i] + "");
System.out.println ("\ n Array copy complete! ");
18}
19}
Output Result:
A1 the contents of the array: 1 2 3 4 5
A2 the contents of the array: 1 2 3 6 5 4 3
Array copy complete!
System.arraycopy (source,0,dest,0,x): The meaning of the statement is: Copy the source array from the subscript 0 starting from the X element to the target array, from the target array of subscript 0 corresponding to the location to start access.