One, the Declaration and allocation of arrays
Int[] scores = new INT[5];
Second, the assignment value:
Int[] scores = {35,58,95,56,12};
Third, use the loop operation array:
The array name. length is used to get the lengths of the array
Four, using the Arrays class operation array:
Arrays class in the Java.util package, you need to refer to the
Common methods of the arrays class:
1. Sorting
Arrays.sort (array name);
2. Converting an array into a string
Arrays.tostring (array name);
3. Assigning values to arrays
Arrays.fill (array name, value);//each element in the array is assigned value
Arrays.fill (array name, fromindex,toindex,value);//the assignment from coordinates fromIndex to toIndex-1 in an array is value
4. Compare whether elements are equal
Arrays.equals (array name 1, array name 2);
5. Finding the range of elements using the dichotomy method
Arrays.binarysearch (array name, value);//value the coordinates in the array, returns a negative number if it does not exist
V. Manipulating arrays with foreach
for (element type element variable: Traverse object)
{
Code to execute
}
#思考问题 # What do you do if you want to get the subscript of an array element in a foreach statement?
Six or two-D arrays
Use a double loop to iterate through the array.
Use of Java arrays