
9.7 The ArrayList Class 617
Figure 9.15
Output of Example 9.12
9.7.4 Using the ArrayList Class in a Program
Now let’s see how we can use the ArrayList class in a Java program. Going
back to our example of a bookstore and a search engine, we want to design
and code a simple program that enables users to search for books.
We will have three classes in this program:
■
a Book class, encapsulating the concept of a book
■
a BookStore class, encapsulating the concept of a bookstore
■
a BookSearchEngine class, including the main method, which pro-
vides the user interface.
In the interest of keeping things simple, our Book class will contain only
three instance variables: ...