Import Java.util.Arrays;
public class arraysdemo{
public static void Main (string[] args) {
int [] arraysrc1={1,3,4,5,6,2};
Copy data, no value default 0;
int [] arraydes1=arrays.copyof (arraysrc1,10);
for (int i=0;i<arraydes1.length;i++) {
System.out.print (arraydes1[i]+ "");
}
Copies the specified range of data within the specified array, subscript 2-subscript 4,4-2=2 number;
int [] Arraydes2=arrays.copyofrange (arraysrc1,2,4);
for (int i=0;i<arraydes2.length;i++) {
System.out.print (arraydes2[i]+ "");
}
The comparison of the array. Compares the specified array with the original array is not the same, exactly as true;
int [] arraysrc2={1,3,4,5,6,2};
Boolean flag=arrays.equals (ARRAYSRC1,ARRAYSRC2);
SYSTEM.OUT.PRINTLN (flag);
Array padding
int [] arraydes3=new int[10];
All data in the array is populated with 10;
Arrays.fill (arraydes3,10);
Specify a range fill, subscript 1-subscript 5, altogether 5-1 = 4 numbers are filled;
Arrays.fill (arraydes3,1,5,10);
for (int i=0;i<arraydes3.length;i++) {
System.out.print (arraydes3[i]+ "");
}
Sorts the array, from small to large.
Arrays.sort (ARRAYSRC1);
for (int i=0;i<arraysrc1.length;i++) {
System.out.print (arraysrc1[i]+ "");
}
The method of binary method finding
int Index=arrays.binarysearch (arraysrc1,5);
System.out.print (index);
Copy an array using the methods of the System class
int [] arraydes5=new int[10];
System.arraycopy (arraysrc1,0,arraydes5,2,5);
for (int i=0;i<arraydes5.length;i++) {
System.out.print (arraydes5[i]+ "");
}
}
}
Java applet 3Arrays (2015-8-27)