July 2023
Intermediate to advanced
276 pages
6h 55m
English
The Comparator interface is used in hundreds of places in the JDK library, from searching operations to sorting, reversing, and so on. This good old interface has turned into a functional interface; the benefit is that we can use charmingly fluent syntax to implement comparators.
Let’s create a few different implementations of the Comparator to understand the influence of the functional style. Our fingers will thank us for all the keystrokes saved by not having to create anonymous inner classes.
We’ll build an example to sort a list of people using a few different points of comparison. Let’s first create the Person JavaBean.
| | public class Person { |
| |
Read now
Unlock full access