Part II. Collections

The Java Collections Framework is a set of interfaces and classes in the packages java.util and java.util.concurrent. They provide client programs with various models of how to organize their objects, and various implementations of each model. These models are sometimes called abstract data types, and we need them because different programs need different ways of organizing their objects. In one situation, you might want to organize your program’s objects in a sequential list because their ordering is important and there are duplicates. In another, a set might be the right data type because now ordering is unimportant and you want to discard the duplicates. These two data types (and others) are represented by different interfaces in the Collections Framework, and we will look at examples of their use in this chapter. But that’s not all; none of these data types has a single “best” implementation—that is, one implementation that is better than all the others for all the operations. For example, a linked list may be better than an array implementation of lists for inserting and removing elements from the middle, but much worse for random access. So choosing the right implementation for your program involves knowing how it will be used as well as what is available.

This part of the book starts with an overview of the Framework and then looks in detail at each of the main interfaces and the standard implementations of them. Finally we will look at the special-purpose ...

Get Java Generics and Collections 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.