The point of the data is 100. The integer variable definition has no array: int i1; int i2int i3
Define int I [100] with array;
Array definition: int I [100]; It's just pseudocode, just one meaning.
(1) one-dimensional array
One-dimensional arrays can store tens of millions of data, and these data types are exactly the same.
To use java arrays, you must go through two steps: declaring arrays and allocating memory to arrays.
Report 1
Declare a one-dimensional array: data type array name [] = null;
Memory not allocated to array: array name = new data type [length];
Statement 2
Declare a one-dimensional array: data type [] Array name = null.
(2)java data types are divided into two categories.
1. Basic data type
Int, long operation itself is the concrete content.
Reference data types: array, class, interface.
Reference conveys the right to use a memory, a memory space, which may be used by many people at the same time.
2. Case declaration array
In the declaration format of array, data type is the data type of array elements, such as integer, floating point and character.
Array names are used to unify the names of this group of elements with the same data type, and their naming rules are the same as those of variables.
After the array is declared, the name of the array is actually stored in the stack memory, and it is concluded that the memory needed by the array should be configured in the stack memory. Fixed production tells the compiler how many elements to store in the declared array, and new tells the compiler to store them according to the length in parentheses.
The basic data type even reading has its default value: int 0;; As long as it is a reference data type, the default value is null case.
Allocate memory space when declaring an array.
Declare an array without allocating memory.
Data type array name [] = new data type [number]
int score[]= new int[ 10];
Declare an integer array score with the number of elements of 10, and at the same time open up the use time limit according to the memory space.
In java, the space occupied by plastic data type is 4 byte, and the whole array score can save 10 elements. So the memory occupied by the above example * * * is 4* 10=40 bytes.
(3) Access to the array
Representation of elements in an array
You can access the elements in an array by using an index. The array index number of java starts from 10. Take a plastic array with score [10] as an example, and score[0] represents the first element.
All the way down, the last one is score[9]
(4) get the length of the array
Obtaining the length of an array (that is, the length of an array element) in java can be done by using the array name. Length.
Array name. Length-Returns data of type int.
(5) Static initialization of array
The previous arrays were dynamically initialized, and all the contents were not specified when the array was declared, but appeared as default values.
Static initialization refers to specifying specific contents for an array directly after it is declared.
If you want to assign an initial value to the array directly at the time of declaration, you can use braces, just add the assignment of the initial value after the life format of the array.
Data type array name [] = {initial value 0, initial value 1, initial value 3, ... initial value n };;
Example sorting, commonly used sorting in operation, from big to small.
Don't be confused by the value of I at this time if (score [I] >; score[j]){
In contrast, the main knowledge of this step is actually sorted according to the value of J after completion.
(6) Two-dimensional array
Two-dimensional arrays are declared in a similar way to arrays, and the keyword new is also used for memory allocation.
In fact, the format of declaring and allocating memory is as follows
Dynamic initialization
Data type array name [] [];
Array name = new data type [number of rows] [number of columns];
Declare and initialize an array
Data type array name [] [] = new data type [number of rows] [number of columns];
Static initialization
(7) storage of two-dimensional array
Declare two-dimensional array scores and open up a memory space at the same time.
int score[][]= new int[4][3];
The total data score can store 4*3= 12 elements. In java, the space occupied by int data type is 4 bytes, so the memory occupied by plastic array is 4* 12=48 bytes.
example
(8) Static initialization of two-dimensional array
The space will only be opened when it is used, and it will not be opened when it is not used (the red part). Multidimensional arrays are generally only understood by two-dimensional arrays and three-dimensional arrays.