Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How does JAVA declare arrays?
How does JAVA declare arrays?
There are several ways to define arrays in Java:

Long [] number; //Common definition methods can be divided into static and dynamic definition methods, which are explained below.

Long number []; //Usage is the same as above.

Long ... numbers; //can only be used to define parameters in a function.

[] Long numbers; //definition error, there is no such writing.

Static definition:

int[] numbers = { 1,2,3,4,5 };

Dynamic definition:

int size = 5;

int[]numbers = new int[size];

for(int I = 0; I< size; i++) {

Number [I] = I+1;

}

Definition of formal parameters of int ... xx:

Public void testArray(int ... number) {

for (int i : numbers) {

//Print all elements of the passed parameter.

system . out . println(I);

}

}