Element data type [] Array variable name;  code>
 
 -  ② Element creation and substitution (content creation)  dd>
 
 Array variable name = new Element data type [number of elements];  code> * When using new
  Element data type [] Array variable name = new Element data type [Number of elements];  code>
| Data type | initial value | 
|---|---|
| Numeric type | 0 | 
| boolean type | false | 
 score.length  code> contains "5"  dd>
  ・  i  code> contains "0-4"  dd>
   How to write  strong>  dd>
 `for (int i = 0; i Extended for statement
   How to write  strong>  dd>
 `for (element type arbitrary variable name: array variable name) {
 }`
  → The contents of the variable are updated every week the loop  dd>
How the array is processed behind the scenes
   First of all ...  strong>  dd>
 ʻInt [] score = new int {5} is executed `
  ① An array with 5 int type elements is created in memory  dd>
  ② Int [] type array element, score is created in memory  dd>
  ③ The position information in memory at the beginning of the array (0) is assigned to score  dd>
   After that ...  strong>  dd>
 `When score {2}` is executed on the program`
  ④ The address in memory at the beginning (0) of the score is searched  dd>
  ⑤ Read and write the {2}th memory from the beginning
Garbage collection
  Normally, variables created in an if block are not applied when the block disappears.  dd>
 The elements secured by  new do not disappear even after the block ends, and remain as garbage in the memory.  dd>
  The Java feature that automatically removes these is  garbage collection.  strong>  dd>
null value
	  if ( b== true) {
		int[] i = {1,2,3};
        i=null;
	   }
As described above, by assigning a null value, the memory where the variable value is stored is no longer referenced.
Multidimensional array
  Declaration of 2D array  dd>
 `Element type [] [] Array variable name = new Element type [number of rows] [number of columns]`
  Description method when using elements of a two-dimensional array  dd>
 `Array variable name [row number] [column number]`
  How to initialize a two-dimensional array  dd>
 `Element type [] [] Array variable name = {// 1st row {// 1st column number of elements // 2nd column number of elements // 3rd column number of elements ...}, // 2nd row { }, // 3rd line ...} `
        
          
          
            Recommended Posts