Chapter 3 Generics and Collections
THE OCP EXAM TOPICS COVERED IN THIS CHAPTER INCLUDE THE FOLLOWING:
- ✓ Generics and Collections
- Create and use a generic class
- Create and use ArrayList, TreeSet, TreeMap and ArrayDeque objects
- Use java.util.Comparator and java.lang.Comparable interfaces
- Iterate using forEach methods on Streams and List
- Use method references with Streams
- ✓ Advanced Java Class Design
- Create and use lambda expressions
- ✓ Generics and Collections
- Filter a collection using lambda expressions
- ✓ Java Stream API
- Use of
merge()
andflatMap()
methods of the Stream API
- Use of
You learned about ArrayList
on the OCA. This chapter covers the rest of the Java Collections Framework that you need to know for the exam. This includes other lists, sets, queues, and maps. The thread-safe collection types will be discussed in Chapter 7, “Concurrency.”
We will also discuss how to create your own classes and methods that use generics so that the same class can be used with many types. You’ll learn how to customize searching and sorting using Comparable
and Comparator
. We will end with some methods that use functional interfaces, such as forEach()
and merge()
.
In the next chapter, we will cover the Stream API. Note that the exam objectives are sloppy and sometimes use “stream” to include “stream” and “lambda.” The merge()
method is on Map
and not really a stream API.
Reviewing ...
Get OCP Oracle® Certified Professional Java® SE 8 Programmer II now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.