Chapter 8. The Main Interfaces of the Java Collections Framework
A collection is an object that provides access to a group of objects, allowing them to be processed in a uniform way. A collections framework provides a uniform view of a set of collection types specifying and implementing common data structures, following consistent design rules so that they can work together.
Figure 8-1 shows the main interfaces of the Java Collections Framework, all in the package java.util, together with one other—java.lang.Iterable—which is outside the framework. Iterable (see “Iterable and Iterators”) defines the contract (see “Contracts”) that a class—any class, not only one of those in the framework—must implement in order to be used as the target for an “enhanced for statement,” usually called a foreach statement.
Figure 8-1. The main interfaces of the Java Collections Framework
The interfaces in Figure 8-1—together with the subinterfaces that we will meet in this chapter—define the structure and functionality of the Collections Framework. You should choose the collections to use in a program according to the functionality of the interfaces as described here, and as far as possible your variables should have interface rather than implementation types. The choice of implementations comes later in program design.
The central interface in Figure 8-1 is Collection, which exposes the core ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access