Static and dynamic initialization of one-dimensional and two-dimensional arrays in Java

Today we're going to talk about arrays in Java, including static initialization and dynamic initialization of one-dimensional arrays and two-dimensional arrays

Array overview:

Array can be regarded as a combination of multiple data of the same type, and the unified management of these data;

Array variables belong to the reference data type, and arrays can also be regarded as objects. Each element in the array is equivalent to the member variables of the object;

The elements in the array can be any data type, including basic data type and reference data type;

Declaration of one-dimensional array:

Declaration method: for example; int a [ ] = new int [3];

In the Java language, the declaration cannot specify its length [number of elements in the array];

Illegal declaration; int a [5];

Creation of array objects:

One dimensional array initialization

Dynamic initialization:

initiate static

Two dimensional array

A two-dimensional array can be regarded as an array of elements, for example:

2D array initialization

Static initialization:

Dynamic initialization:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>