The comparingLong(java.util.function.ToLongFunction) method of Comparator Interface in Java accepts a function as parameter that extracts an long sort key from a type T, and returns a Comparator that compares by that sort key.The returned comparator is serializable if the specified function is also serializable.
static <T> Comparator<T> comparingLong(ToLongFunction <T> keyExtractor)
Parameters: This method accepts a single parameter keyExtractor which is the function used to extract the long sort key.
Return value: This method returns a comparator that compares by an extracted key
Exception: This method throws NullPolongerException if the argument is null.
Below programs illustrate comparingLong(java.util.function.ToLongFunction) method:
The output printed on console of IDE is shown below.
The output printed on console is shown below.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.