Java array memorandum, java Array
Preface
Recently, when I used Java for ACM, I often forgot how to implement static initialization for arrays. So here I will record the common knowledge of Java arrays.
Java array knowledge
An array is an object in Java, and an array instance needs to be created using the new operator.
Common knowledge:
Java array Initialization
Java array initialization includes dynamic initialization and static initialization.
Take an array of the int type as an example to introduce static initialization and dynamic initialization respectively.
Static Initialization
int[] array = new int[] {1, 2, 3, 4, 5, 6};
The code above shows that static Initialization is to display the initial values of each element in the specified array, and the length of the array is determined by the system.
Dynamic Initialization
int[] array = new int[6];
From the code above, we can see that dynamic initialization only specifies the length of the array, and the system assigns the initial value to the array.
For different types, the initial values assigned by the system are also different.
| Type |
Initial Value |
| Integer type (byte, short, int, long) |
0 |
| Floating point type (float, double) |
0.0 |
| Character type (char) |
'\ U000000' (Space) |
| Boolean) |
False |
| Reference Type (class, interface, array) |
Null |
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.