How to declare an array?

 Posted by Kmandapalli on 2/26/2014 | Category: OOPS Interview questions | Views: 810 | Points: 40
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 

Comments or Responses

Login to post response