Steps to use the array:
(1) declaring an array
Declaring a one-dimensional array in Java
The syntax is as follows:
Array type [] array name;
Or
Array type array name [];
(2) Allocating space
The syntax is as follows:
Array name =new data type [array length];
You can combine the declaration array, the allocation space,
The syntax is as follows:
data type [] array name =new data type [array length];
(3) Assign value
The syntax is as follows:
Array name [subscript value];
The declaration array, allocation space, and assignment can be combined to complete
The syntax is as follows:
data type [] Array name ={value 1, value 2, value 3, value 4, value 5,......, value N,};
Note: Creating and assigning values directly is generally used in cases where the array element is less. He must complete it, and the following code is not legal:
Int[] score;
SCORE={60,70,98,90,76}; Error
(4) Processing of data
array element Initial value
|
Data type |
Initial value |
|
Int |
0 |
|
Double |
0.0 |
|
Char |
' \u0000 ' |
|
Bollean |
False |
Array sort, Syntax:
Arrays.sort (array name);
Arrays is a class provided in Java, and sort () is a method of the class. By the syntax above, the array name is placed in parentheses of the sort () method, and the array can be sorted. Therefore, after this method executes, the elements in the array are ordered (ascending).
The contents of the output array, syntax:
Arrays.tostring (array name);
S1/using Java to understand program logic/08-Arrays