Contents    Page-10    Prev    Next    Page+10    Index   

Arrays

An array is a contiguous group of elements, all of the same type, indexed by an integer. In a sense, the array is the most basic data structure, since the main memory of a computer is essentially one big array.

The major advantage of an array is random access or O(1) access to any element. (Paging and cache behavior can add significantly to access time, but we will ignore that.)

The major disadvantage of an array is rigidity:

In Java, an array is an Object, so it is possible to expand it in effect by making a new larger array, copying the old array contents into the new array, and letting the old array get garbage-collected.