Try it,
1. Arrays are consecutive memory locations which are stored in Heap, as Arrays are objects in java.
2. Assume i have an Array of String as an instance variable
String [] arr = {1,2,3,4,5};
Now it looks like
arr [0] = 1
arr [1] = 2
arr [2] = 3
arr [3] = 4
arr [4] = 5
{1,2,3,4,5} are stored over the heap, and Considering array "arr" as instance variable, will lives within the object on the heap.
Now arr will contain the address of the very first element of the array, which is 1 . "arr", which is a variable of an array of objects, will be inside the object and {1,2,3,4,5} out of the heap.
source share