Array-Based Structures

This chapter discusses general-purpose array-based structures. Each of these classes has an array as a field. We present implementations of the Stack and Queue interfaces from Chapter 4, as well as a new interface List and one implementation of it.

An array has a fixed lengthit can't get any longer or shorter. Section 5.1 presents techniques for getting around this problem, in the context of developing a class to represent a deck of playing cards.

Section 5.2 shows how to implement the Stack and Queue interfaces. Section 5.3 presents the List interface and the ArrayList class which implements it. The Iterator interface, explained in Section 5.4, is a general-purpose technique for traversing a Listthat is, doing something with or to each element of the List.

These structures are so commonly used that standard implementations are built into Java. Section 5.5 introduces the Java collections framework, which provides many useful general-purpose data structures.

Категории