An array is a data structure used to store a collection of values of the same type. Each value in the array can be accessed through an integer subscript.
Common actions are as follows:
- declaring an array;
- initialization of arrays;
- View array length;
- For Each loop;
- Array copy;
- Array sorting;
- Converts an int array to a string;
- two-dimensional array;
1. Declaring arrays
Syntax: data type [] array name;
Or a data type array name [];
2, array initialization
3. Get the array length
4. For Each loop
foreach is not a keyword in Java, it is a special simplified version of A for statement, which is simpler and easier to iterate through arrays and collections.
Syntax: for (element type element variable: Traversal object) {
Execute code
}
5. Array copy
If you want to copy all the values in an array to a new array, use the Copyof method of the A soft Ayung class:
6. Array sorting
Syntax: Arrays.sort (array name);
7. Converting an int array to a string
8, two-dimensional array
1. Declaring arrays and allocating space
data type [] Array name = new data type [number of rows] [number of columns]
Example:
Some common operations for arrays in Java