Array of memory
1. In-memory arrays
An array is a reference memory, an array reference variable is simply a reference, and array elements and arrays of variables are stored separately in memory.
The actual array objects are stored in the heap memory (heap), and the reference variables of the array are stored in the stack memory.
PackageCom.java.array; Public classArraytest { Public Static voidMain (string[] args) {//defining and statically initializing an array int[] array1={1,2,3}; //To define and dynamically initialize an array int[]array2=New int[4]; //length of output array2System.out.println ("Array2 Length:" +array2.length); //loop output array1 elements of an array for(inti=0;i<array1.length;i++) {System.out.println (array1[i]); } System.out.println ("---------------------------------"); //array elements for looping output array2 for(inti=0;i<array2.length;i++) {System.out.println (array2[i]); } array2=array1; //output the length of the array2 againSystem.out.println ("Length of array2" +array2.length); }}
When running the above code, the specific memory analysis diagram is as follows:
Java talking about the memory analysis of arrays (I.)