8.9. Arrays

An array is a simple and efficient data structure used in virtually all programming languages. Arrays are used principally to provide constant-time access to a fixed-size collection of primitive datatypes or objects and are a way of referring to many distinct values by a single identifier. Arrays are implemented as real objects with the following properties:

  • Their length can be determined through the length field.

  • They can be assigned to variables of type Object as well as to variables of their specific type.

  • Arrays are efficiently passed to methods by reference just like any other Object.

Array indexing is zero-based, so elements in an array of 10 values can be referred to with subscripts from 0 through 9. Arrays are normally created ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.