Follow these steps to implement the example:
- 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.
- 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> ...