1. What is the initialization of an array?
is to open up a continuous memory space for the array and assign a value to each array element.
2. How to initialize the array
1. Dynamic initialization
Only specify the length, and the system will initialize it Value
int[] arr = new int[5];
Recommended related video tutorials: java video tutorial
2. Static initialization
gives the initialization value, given by The system determines the length
3. Dynamic initialization format:
数据类型[] 数组名 = new 数据类型[数组长度];
4. Case:
Integer type: byte, The default initialization values of short, int, and long are all 0
Floating point type: The default initialization value of float and double is 0.0
Boolean type: booleanThe default initialization value is false
Character type: char default initialization value '\u0000'
char: The two bytes occupied in the memory are 16 binary bits
\u0000: Each 0 actually represents Hexadecimal 0, then four 0s represent 16 binary digits
[I@19bb25a: [represents an array, a few represent several dimensions, I represents int type, @ is fixed, 19bb25a represents the address value of the array
The example is as follows:
class Demo2_Array { public static void main(String[] args) { //数据类型[] 数组名 = new 数据类型[数组长度]; int[] arr = new int[5]; //动态初始化,在内存中开辟连续的5块空间 System.out.println(arr[0]); //系统给出默认初始化值,整数类型的都是0 arr[0] = 10; System.out.println(arr[0]); System.out.println(arr); //[I@19bb25a } }
For more related articles and tutorials, please visit: java introductory learning
The above is the detailed content of Java implements dynamic initialization of arrays. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools