[J2SE Fast Forward] - Arrays (and their memory analysis)
Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/huyuyang6688/article/details/43091009
Early in the study of other languages such as C, VB, C#, C++, etc. also studied the array, usually the project is often used, but never carefully then in-depth understanding, here to learn Java and encountered, re-organized.
A one-sentence summary of what an array is: an array is a collection of data that has a set of the same data type.
Array variables are reference types, and arrays can also be thought of as objects, with each element of the array being equivalent to a member variable of that object. The type of each element in the array can be of any data type.
Array definition and initialization
The declaration of an array can be thought of as the process of allocating space in memory for each element of the array; the initialization of an array can be thought of as the process of assigning values to the allocated space.
Definition of an array
The format of defining an array in Java is: type variable name, e.g. int arr;
<pre name="code" class="java">int arr; arr=new int;
The code int arr defines an array variable named arr, allocating only one variable in stack memory with empty contents. As shown below.