Java array declaration, creation and initialization basis

Declaration method of one-dimensional array: type var []; Or type [] VaR; When declaring an array, its length (number of elements in the array) cannot be specified. In Java, the keyword new is used to create an array object. The format is: array name = new, type of array element [number of array elements] instance: testnew.java: program code:

Initialization: 1 Dynamic initialization: array definition is carried out separately from the operations of allocating space and assigning values to arrays; 2. Static initialization: allocate space and assign values to array elements while defining numbers; 3. Default initialization: the array is a reference type, and its elements are equivalent to the member variables of the class. Therefore, after the array allocates space, each element is also initialized according to the rules of member variables. Example: testd Java (dynamic): program code:

TestS. Java (static): program code:

TestDefault. Java (default): program code:

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
分享
二维码
< <上一篇
下一篇>>