The definition of two-dimensional array in JAVA (underlying memory diagram)

First of all, the definition of a two-dimensional array in Java is as follows:

int[][] arr = new int[3][2];

This means that a two-dimensional array of int type is defined.
There are three one-dimensional arrays in the array, and each one-dimensional array has two elements.
insert image description hereinsert image description hereinsert image description hereinsert image description hereinsert image description hereinsert image description hereinsert image description hereinsert image description here
.
.
.

Yet another definition of a two-dimensional array

int[][] arr = new int[3][];

This defines that there are three one-dimensional arrays in the array, but the elements in the array are uncertain and need to be defined again
:

int[][] arr = new int[3][];

这个分别对数组中的小数组进行初始化
int[0] arr = new int[3];

int[1] arr = new int[2];

int[2] arr = new int[4];

insert image description here

Image link : Baidu Cloud

Guess you like

Origin blog.csdn.net/weixin_42947972/article/details/101177033#comments_26212829