Java Reference
In-Depth Information
CHAPTER 7
Data Structures and Collections
Almost all applications perform tasks against user data. Sometimes data is obtained
from a user, tasks are performed against the data, and the result is returned immediately.
More often, data is obtained, and then it is stored within the application for later use, and
eventually tasks are performed against it. Applications make use of data structures to
store data that can be utilized thoroughout the lifetime of an application instance. The
Java language contains a number of data structures that are known as Collection
types, and they can be utilized for this purpose. These data structures implement the
java.util.Collection interface, which provides a variety of methods that are
useful for adding, removing, and performing tasks against the data that is used with the
collection.
Java 8 changed the game when it comes to data structures and Collection types.
The concepts of pipelines and streams were introduced, enabling easy iteration and op-
erations against data contained within Collection types. In prior releases of Java, the
developer had to tell the compiler how to iterate over data within a Collection .
Oftentimes in the past, developers utilized a loop to perform iterative tasks on data
structures. Java 8 enabled developers to begin utilizing streams for iterative tasks on
Collection types. When using streams and pipeline of operations on collections, the
developer specifies what type of operation to perform, and the JDK decides how to do it.
This reduces the burden on a developer by reducing boilerplate code, and providing an
easy-to-use algorithm for working with collections.
This chapter introduces some of the data structures that can be utilized within a Java
application for the storage of user data. It discusses some of the data structures in detail,
and introduces operations that can be performed on the data. The concepts of pipelines
and streams are introduced in this chapter, and it provides recipes that demonstrate their
usage. Java 8 forces developers to think differently about the way that they write collec-
tion code, enabling smarter and more productive solutions.
Search WWH ::




Custom Search