KnowledgeBoat Logo
|

Computer Applications

What do you understand by an array ? What is the significance of arrays ?

Java Arrays

13 Likes

Answer

An array is a collection of variables of the same type that are referenced by a common name. It is a reference data type which stores data values in contiguous memory locations. An array is declared and initialized as follows:

int arr[] = new int[10];

The significance of arrays are as follows:

  1. Easy to specify — The declaration, allocation of memory space, initialization can all be done in one line of code.
  2. Free from run-time overheads — There is no run-time overhead to allocate/free memory, apart from once at the start and end.
  3. Random access of elements — Arrays facilitate random (direct) access to any element via its index or subscript.
  4. Fast Sequential Access — It is usually faster to sequentially access elements due to contiguous storage and constant time computation of the address of a component.
  5. Simple code — As arrays facilitate access of multiple data items of same type through a common name, the code becomes much simpler and easy to understand.

Answered By

8 Likes


Related Questions