© Ralph Lecessi 2019
Ralph LecessiFunctional Interfaces in Javahttps://doi.org/10.1007/978-1-4842-4278-0_10

10. Use in Comparing Objects

Ralph Lecessi1 
(1)
Kendall Park, NJ, USA
 

Functional interfaces have changed the way data is compared in Java. This is due to the enhancements to the Comparator interface and the addition of several methods that utilize it in the Java API.

Section 10.1: The Comparator Interface

Comparator is a functional interface that is used to compare two objects. A Comparator is specified with type parameter T. Its functional method, called compare, takes two arguments of type T and returns an integer.
@FunctionalInterface
public interface Comparator<T>
{
    int compare(T o1, T o2);
    ...
}
The result of the compare method is as follows: ...

Get Functional Interfaces in Java: Fundamentals and Examples 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.