Chapter 8. Collection API enhancements
This chapter covers
- Using collection factories
- Learning new idiomatic patterns to use with List and Set
- Learning idiomatic patterns to work with Map
Your life as a Java developer would be rather lonely without the Collection API. Collections are used in every Java applications. In previous chapters, you saw how useful the combination of Collections with the Streams API is for expressing data processing queries. Nonetheless, the Collection API had various deficiencies, which made it verbose and error-prone to use at times.
In this chapter, you will learn about new additions to the Collection API in Java 8 and Java 9 that will make your life easier. First, you learn about the collections factories in Java 9—new additions that simplify the process of creating small lists, sets, and maps. Next, you learn how to apply idiomatic removal and replacement patterns in lists and sets thanks to Java 8 enhancements. Finally, you learn about new convenience operations that are available to work with maps.
Chapter 9 explores a wider range of techniques for refactoring old-style Java code.
Java 9 introduced a few convenient ways to create small collection objects. First, we’ll review why programmers needed a better way to do things; then we’ll show you how to use the new factory methods.