Accepts a function that extracts a sort key from a type T
, and
returns a Comparator<T>
that compares by that sort key using
the specified Comparator
.
The returned comparator is serializable if the specified function and comparator are both serializable.
<T> | the type of element to be compared | |
<U> | the type of the sort key | |
keyExtractor | the function used to extract the sort key | |
keyComparator | the Comparator used to compare the sort key |
Comparator
NullPointerException | if either argument is null |
@apiNote
For example, to obtain a Comparator
that compares
Person
objects by their last name ignoring case differences,
Comparator<Person> cmp = Comparator.comparing(
Person::getLastName,
String.CASE_INSENSITIVE_ORDER);
Diagram: Comparator