Chapter 8. Working with Java Collections
This chapter introduces Java’s interpretation of fundamental data structures, known as the Java Collections. These abstractions are core to many (if not most) programming types and form an essential part of any programmer’s basic toolkit. Accordingly, this is one of the most important chapters of the entire book and provides functionality that is essential to virtually all Java programmers.
In this chapter, we will introduce the fundamental interfaces and the type hierarchy, show how to use them, and discuss aspects of their overall design. Both the “classic” approach to handling the collections and the newer approach based on the Java Streams API will be covered.
Introduction to Collections API
The Java Collections are a set of generic interfaces that describe the most common forms of data structure. Java ships with several implementations of each of the classic data structures, and because the types are represented as interfaces, development teams can, and have, developed their own, specialized implementations of the interfaces for use in their own projects or to share as libraries.
The Java Collections define two fundamental types of data structures. A
Collection is a grouping of objects, while a Map is a set of
mappings, or associations, between objects. The basic layout of the Java
Collections is shown in Figure 8-1.
Note that there are two separate, disjoint type hierarchies represented in the
diagram—Collection
and Map do not have ...
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