The comparingDouble(java.util.function.ToDoubleFunction) method of Comparator Interface in Java accepts a function as parameter that extracts an double 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> comparingDouble( ToDoubleFunction <T> keyExtractor)
Parameters: This method accepts a single parameter keyExtractor which is the function used to extract the double sort key.
Return value: This method returns a comparator that compares by an extracted key
Exception: This method throws NullPointerException if the argument is null.
Below programs illustrate comparingDouble(java.util.function.ToDoubleFunction) 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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.