Hi all,
I want to know where are the arrays basically stored?? Heap or stack???
Thank you.
Printable View
Hi all,
I want to know where are the arrays basically stored?? Heap or stack???
Thank you.
i think array are placed in heap because in stack
The Java system must know, while it is creating the program, the exact lifetime of all the items that are stored on the stack
But what if i declare an array irrespective of its type inside the method. Isn't that supposed to go on stack according to java memory doctrines???
Where do you think it gets stored and why?
May be i guess it all depends on the its definition than on its type. I mean irrespective of primary or reference type it all goes where the user is defining it, inside the method or outside of it. Correct me if am wrong. I need some clear view on this one.
Thank you.
You can think of an array as an object which holds x items
Is somewhat similar toCode:public class MyArray{
public int length = 3;
int value1;
int value2;
int value3;
}
I must admit this example was found on another post, available here: Java Array is stored in stack or heap? - Stack OverflowCode:int[] x = new int[3];
Arrays are stored on the heap.