This is the usual way for declare a Java array:
int[] arr = new int[100];
But this array is using heap space. Is there a way we can declare
Arrays are dynamically allocated so they go on the heap.
I mean, what happens when you do this:
int[] arr = new int[4];
arr = new int[5];
If the first allocation was done on the stack, how would we garbage collect it? The reference arr
is stored on the stack, but the actual array of data must be on the heap.