Computer Applications
What is an array ? What is the need for arrays ?
Java Arrays
1 Like
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 use of arrays have the following benefits:
- Easy to specify — The declaration, allocation of memory space, initialization can all be done in one line of code.
- Free from run-time overheads — There is no run-time overhead to allocate/free memory, apart from once at the start and end.
- Random access of elements — Arrays facilitate random (direct) access to any element via its index or subscript.
- 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.
- 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
1 Like
Related Questions
Given the following array :
Which sorting algorithm would produce the following result after three iterations
Given the following array :
Which sorting algorithm would produce the following result after three iterations.
What are different types of arrays? Give examples of each array type.
Write a note on how single-dimension arrays are represented in memory.