【发布时间】:2018-02-04 04:48:07
【问题描述】:
一个代码sn-p
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?
有没有一种叫做动态内存分配的东西?
【问题讨论】:
-
动态内存分配给数组
ArrayorArrayList? -
这是堆。每当您看到
new这个词时,就会有一些事情发生。 -
不确定您所说的“动态”是什么意思。数组创建后无法更改其大小,但您可以在运行时随意创建新数组(并选择其大小)。
-
并且所有的对象分配(包括数组)都使用堆。见*.com/questions/10953806/…
标签: java heap-memory dynamic-memory-allocation stack-memory