Returns a lexicographic-order comparator with another comparator.
If this Comparator
considers two elements equal, i.e.
compare(a, b) == 0
, other
is used to determine the order.
The returned comparator is serializable if the specified comparator is also serializable.
other | the other comparator to be used when this comparator compares two objects that are equal. |
NullPointerException | if the argument is null. |
@apiNote
For example, to sort a collection of String
based on the length
and then case-insensitive natural ordering, the comparator can be
composed using following code,
Comparator<String> cmp = Comparator.comparingInt(String::length)
.thenComparing(String.CASE_INSENSITIVE_ORDER);
Diagram: Comparator