Java 对象内存执行分析-Array(三)

Arrays in Java store one of two things: either primitive values (int, char, ...) or references (a.k.a pointers).java

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"来建立,会在堆内存中分配而且返回一个引用。这也一样适用数组,由于数组是对象。指针

  1. 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.code

int数组arr 仅仅是三个Integer对象的数组的引用。若是你建立一个10个integer的数组,它是和一个数组相同分配在内存中,而且返回一个引用。对象

输入图片说明

  1. 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.it

多维数组也是相同的规则。io

相关文章
相关标签/搜索