Chapter 7

Arrays and Other Data Structures

COMPUTERS GET A LOT OF THEIR POWER from working with data structures. A data structure is an organized collection of related data. An object is a type of data structure (although it is in fact more than this, since it also includes operations or methods for working with that data). However, this type of data structure -- consisting of a fairly small number of named instance variables -- is only one of the many different types of data structure that a programmer might need. In many cases, the programmer has to build more complicated data structures by linking objects together. But there is one type of data structure that is so important and so basic that it is built into every programming language: the array.

An array is a data structure consisting of a numbered list of items, where all the items are of the same type. In Java, the items in an array are always numbered from zero up to some maximum value. For example, an array might contain 100 integers, numbered from zero to 99. The items in an array can be objects, so that you could, for example, make an array containing all the Buttons in an applet.

This chapter discusses how arrays are created and used in Java. The last section introduces several other data structures that are available as standard classes in Java.

Sections in Chapter 7:

  1. Creating and Using Arrays
  2. Array Processing
  3. Searching and Sorting
  4. Two-Dimensional Arrays
  5. Other Data Structures

[ First Section | Next Chapter | Previous Chapter | Main Index ]