9.7 The ArrayList Class
As we have seen, single-dimensional and multidimensional arrays are useful in many situations. However, they have limitations.
Let’s say we are designing a search engine for a large website, for example, an online bookstore. The user will type a word in a text field box, our code will access a database, retrieve all the books with titles that contain this word, and return them to the user.
We could store the book information in an array of books. One problem, however, is that we don’t know how many books we will have. There could be 3, 32, 500, or 5,000 books, or maybe even more. Without knowing the number of books, we do not know what size to make the array. The safest bet would be to create the array with the maximum ...
Get Java Illuminated, 5th 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.