Java Reference
In-Depth Information
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) program‐
ming types, and form an essential part of any programmers basic toolkit. Accord‐
ingly, this is one of the most important chapters of the entire topic, and provides a
toolkit 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 (using the Streams
API and the lambda expressions functionality introduced in Java 8) 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 clas‐
sic data structures, and because the types are represented as interfaces, it is very pos‐
sible for development teams to develop their own, specialized implementations of
the interfaces for use in their own projects.
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 .
Within this basic description, a Set is a type of Collection with no duplicates, and
a List is a Collection in which the elements are ordered (but may contain
duplicates).
s
a
 
Search WWH ::




Custom Search