How to do it...

Follow these steps to implement the example:

  1. First, we will implement some auxiliary classes we will use in the example. Create a class named Person with the basic characteristics of a person. Check the Creating streams from different sources recipe to see the source code of this class.
  2. As we'll work with methods that depend on the order of the elements of the stream, we have to override some methods in the Person class. First, we'll override the compareTo() method that compares two persons. We'll create a static Comparator object using the Comparator interface to compare two Person objects using their first name and last name. Then, we'll use that comparator in the compareTo() method:
 private static Comparator<Person> ...

Get Java 9 Concurrency Cookbook - Second Edition 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.