Define how an array of Java

Array define how a

Dynamic mode (the length of the specified array)

format:

Type of stored data array [] = new Array array name type of data stored [length];

[]: Represents an array.
An array of name: from the definition of an array of variable names, identifiers meet specifications, you can use the name manipulate arrays.
new new : keywords, creating keywords used by the array.
Storage array data types: arrays created to see what type of data storage.
[ Length ] : length of the array, the array represents the number of elements in the container can be stored.

example:

It can store three integers defined array of containers, as follows:

int[] arr = new int[3];

 

Array definition Second way

Statically (elements in the array)

format:

Data Type [] = new Array Name Data Type [] {element 1, element 2, element 3 ...};

1,2,3,4,5 storage container defines an array of integers.

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

:( format or omission can not be declared after the assignment, the assignment can only be declared at the same time)

Data Type [] = {array name element 1, element 2, element 3 ...};

1,2,3,4,5 storage container defines an array of integers.

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

note:

   1. If you create an array using the static mode, the system automatically calculate the number of elements of the length of the array

   2. Creating the right side of the array static in brackets can not write length

   3. Creating omitted format static array can not be declared after the first assignment, it can only be declared at the same time direct assignment

Guess you like

Origin www.cnblogs.com/libinhong/p/10988752.html