There's more...

Take into account that if you use the sorted method, you have to provide Comparator that can be applied to the elements you want to sort or the elements of the stream must implement the Comparable interface. In our case, the Person class implements that interface and the compareTo() method to sort the elements of the stream according to their first and last names.

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.