1.fill Method
The Fill method is primarily used to populate arrays, and here we give the simplest type of int (the other types).
Look at arrays's fill source.
Sample code:
Java Code
Publicstaticvoidmain (string[] args) {
INTA[]=NEWINT[5];
Fill filled Array
Arrays.fill (a,1);
for (inti=0;i<5;i++)//Output 5 1
System.out.println (A[i]);
}
populate part of the array source code:
Example:
Java Code
Publicstaticvoidmain (string[] args) {
INTA[]=NEWINT[5];
Fill filled Array
Arrays.fill (a,1,2,1);
for (inti=0;i<5;i++)//a[1]=1, the rest defaults to 0
System.out.println (A[i]);
}
2.sort Method
It is known from the method name that the array is sorted, still with the int type, and the other types are the same.
Same as having the entire array sorted, as
Java Code
Publicstaticvoidmain (string[] args) {
inta[]={2,4,1,3,7};
Arrays.sort (a);
for (inti=0;i<5;i++)/Ascending
System.out.println (A[i]);
}
Specify array partial sorting:
Java code
Publicstaticvoidmain (string[] args) {
inta[]={2,4,1,3,7};
Arrays.sort (a,1,4); Output 2,1,3,4,7
for (inti=0;i<5;i++)
System.out.println (A[i]);
}
3.equals Method
Used to compare whether the values of elements in two arrays are equal, or to see an array of type int. See Arrays Source
Example:
Java Code
Publicstaticvoidmain (string[] args) {
inta[]={2,4,1,3,7};
inta1[]={2,4,1,5,7};
System.out.println (Arrays.equals (A1, a)); Output false
}
4.binarySearch Method
The BinarySearch method can be used to perform the binary search method for the sorted array. Look at the source code as follows
Example:
Java Code
Publicstaticvoidmain (string[] args) {
inta[]={2,4,1,3,7};
Arrays.sort (a);//First sort
System.out.println (Arrays.binarysearch (A, 4));//Two-point lookup, Output 3
}
5.copyof Method
To copy an array, the arrays copyof () method returns an array that is a new array object, so you change the value of the element in the returned array without affecting the original array
Such as:
Java Code
Importjava.util.Arrays;
Publicclassarraydemo {
Publicstaticvoidmain (string[] args) {
Int[] arr1 = {1, 2, 3, 4, 5};
int[] arr2 = arrays.copyof (arr1, arr1.length);
for (inti = 0; i < arr2.length; i++)
System.out.print (Arr2[i] + "");
System.out.println ();
}
}