7.3 Programming with Arrays and Classes

The Moving Finger writes; and, having writ,

Moves on; nor all your Piety nor Wit

Shall lure it back to cancel half a Line.

Nor all your tears wash out a word of it.

—OMAR KHAYYAM, The Ruba'iyat (Fitzgerald Translation)

In this section, we present some additional techniques for working with arrays. In particular, we discuss using an array variable as an instance variable in a class. We begin with a programming example that illustrates some basic techniques.

Programming Example A Specialized List Class

One way to use an array for a special purpose is to make the array an instance variable of a class. The array is accessed only through the class methods, and so you can add any checks and automatic processing ...

Get Java: An Introduction to Problem Solving and Programming, 8th 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.