Answer:
A array can be created by using the 'new' keyword.
Syntax:
arrayRefVar = new dataType[arraySize];
It creates an array using new dataType[arraySize].
It assigns the reference of the newly created array to the variable arrayRefVar.
Declaring an array variable, creating an array, and assigning the reference of the array to the variable can be combined in one statement, as shown below:
dataType[] arrayRefVar = new dataType[arraySize];
Alternatively way to create arrays:
dataType[] arrayRefVar = {value0, value1, ..., valuek};
The array elements are accessed through the index.
Asked In: Many Interviews |
Alert Moderator