![]() |
![]() |
![]() |
![]() |
![]() |
|
To create an array, you need to deploy the new operator,
just as you need to deploy the new operator to create a class
instance.
To signal that an array is to be created, you include the type of the elements to be stored and a bracketed number that specifies how many elements the array is to store. For example, to create an array of four integers, you write the following:
*-- Specifies that a new array is to be created
|
v
-----------
new int [4]
^ ^
| |
| *-- Specifies that the array contains four elements
|
*-- Specifies that the new array contains integer elements