java basics - array

1. Array

It is to set multiple storage units for variables! Except for basic data types, which are passed by value, everything else is passed by reference! 1. One-dimensional array: It is to collect multiple variables of the same data type into a line, and attach subscripts for management. (Subscripts start at 0). Why do subscripts start at zero? Because the array defaults to the memory address of the first subscript. So adding a subscript to a zero is still equal to the default subscript.

image

Note: Once the array is applied, the length of the array will not be changed. The storage space in memory is measured in bytes.

Application method of one-dimensional array: For example, 1: int[] i=new int[3];//Apply a storage space with a length of 3 ints in the memory. For example 2: int[]={123,12,1};//Apply a storage space with a length of 3 ints in the memory and attach the value.

1. Two-dimensional array:

It's an array nested within an array. An array stores references to nested arrays.

image

Like a table, the two-dimensional array has two subscripts, the first subscript is like the row of the table, and the second subscript is like the column of the table. Rows and columns correspond to a storage space.

image

Application method of two-dimensional array: // row and column int[][] t = new int[3][3];

//我不定制列个数
	int[][] t1 = new int[3][];
	
	//那值来定制  长度 和数据
	int[][] t2 = { { 123, 123, 123 },  { 123, 123 },  { 123 } };

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327086342&siteId=291194637