Chapter 3

Using the ArrayList Class

IN THIS CHAPTER

check Working with the ArrayList class

check Creating an array list

check Introducing generics

check Adding elements to an array list

check Deleting elements from or modifying elements in an array list

Some people love to collect things: nick-knacks, baseball cards, postage stamps, dolls — you name it, someone collects it.

If I were a collector of some random thing — say, old tin advertising signs — an array would be a poor choice for storing the data. That’s because on any given day, I may find another tin sign at a yard sale. So if I had 87 tin signs before, and I had created an array big enough to hold all 87 signs, I’d have to change the array declaration to hold 88 signs.

Java’s collection classes are designed to simplify the programming for applications that have to keep track of groups of objects. These classes are very powerful and surprisingly easy to use — at least the basics, anyway. The more advanced features of collection classes take some serious ...

Get Java All-in-One For Dummies, 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.