Arrays in Java store one of two things: either primitive values (int, char, ...) or references (a.k.a pointers).
Arrays 在Java 中存储二者之一: 原始数据类型(int,char,...)或者是引用(a.k.a 指针) When an object is creating by using "new", memory is allocated on the heap and a reference is returned. This is also true for arrays, since arrays are objects.
当一个对象通过使用"new"来创建,会在堆内存中分配并且返回一个引用。这也同样适用数组,因为数组是对象。
- Single-dimension Array
int arr[] = new int[3];
The int[] arr is just the reference to the array of 3 integer. If you create an array with 10 integer, it is the same - an array is allocated and a reference is returned.
int数组arr 仅仅是三个Integer对象的数组的引用。如果你创建一个10个integer的数组,它是和一个数组相同分配在内存中,并且返回一个引用。
- Two-dimensional Array
How about 2-dimensional array? Actually, we can only have one dimensional arrays in Java. 2D arrays are basically just one dimensional arrays of one dimensional arrays.
二维数组是如何实现的?普遍的上,在java中,我们只有一维数组。二维数组基本上仅公是一维数组中的一维数组。
int[ ][ ] arr = new int[3][ ];
arr[0] = new int[3];
arr[1] = new int[5];
arr[2] = new int[4];
Multi-dimensional arrays use the name rules.
多维数组也是相同的规则。