0
Scanner sc=new Scanner(System.in);
System.out.println("enter size of array");
int size=sc.nextInt();
int[] arr=new int[size];//Is the array arr allocated on heap?
有什么所谓的动态分配的内存阵列?
Scanner sc=new Scanner(System.in);
System.out.println("enter size of array");
int size=sc.nextInt();
int[] arr=new int[size];//Is the array arr allocated on heap?
有什么所谓的动态分配的内存阵列?
Java对象驻留在一个称为堆的区域中。 新构建的对象首先分配在一个称为eden的堆区域中。
堆栈包含用于当前方法的范围到对象和原始类型的值的引用:
当我们创建一个原始类型数组时,它在堆内存中创建并且堆栈内存包含它的引用。
int[] arr=new int[size];//Is the array arr allocated on heap?
请注意,没有“数组arr
”。
有一个数组 - 它必然在堆上,因为数组是对象,并且所有的Java对象都驻留在堆上 - 并且存在一个引用,它位于堆栈上,因为它是一个本地变量。
*数组的动态内存分配*'Array'或'ArrayList'? – Ravi
https://stackoverflow.com/questions/14837185/how-can-we-dynamically-allocate-and-grow-an-array – nullpointer
这是堆。每当你看到“new”这个词时,就会发生一些事情。 –