O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required