Define an array:
1. Int [] arr = {90, 80, 70 ....}
2. Int [] arr = new int [10];
3. Int [] arr = new int [] {90, 80, 70 ,...}
In Java, when the = operation is used for the basic data type, the value is copied to the variable, but when it is used for the object, the object is specified to the reference name for reference.
Copy an array:
1. Cyclic Replication
2. system. arraycopy (source, start index, destination, start index, and copy length );
3. copyof ();
Arrays class:
The arrays class is located in the Java. util package. It provides some methods for direct use:
|
Name |
Description |
|
Sort () |
To help you sort the specified array, the quick sort method is used. |
|
Binarysearcy () |
Binary Search for sorted arrays. If a specified value is found, the index of the value is returned. Otherwise, a negative value is returned. |
|
Fill () |
After an array is configured, the default value is given based on the array type. |
|
Equals () |
Checks whether all elements in the two arrays are equal. If yes, true is returned. Otherwise, false is returned. |
| Deepequals () |
Deep comparison of arrays, applicable to arrays larger than two dimensions |
| Deeptostring () |
Deep output of arrays, applicable to arrays larger than two dimensions |
You cannot use = to compare whether the element values of the two arrays are equal, is used to test whether two object names reference the self-consent object, that is, to test whether two names are bound to the consent object.
Foreach and array:
The foreach syntax has been added since j2se 5.0, also known as the enhanced for loop:
For (type element: array)
For example:
Int [] arr = {1, 2, 3 ,}
For (INT element: ARR)
System. Out. println (element );