The thenComparingDouble(java.util.function.ToDoubleFunction) method of Comparator Interface in Java returns a lexicographic-order comparator with a function that extracts a double sort key. This method is applied after comparing method if you want to apply another comparing for those values which are equal in the comparing method.
default Comparator <T> thenComparingDouble( ToDoubleFunction <T> keyExtractor)
Parameters: This method accepts keyExtractor which is the function used to extract the Double sort key.
Return value: This method returns a lexicographic-order comparator composed of this and then the Double sort key.
Exception: This method throws NullPointerException if the argument is null.
Below programs illustrate thenComparingDouble(java.util.function.ToDoubleFunction) method:
The output printed on console of IDE is shown below.
You can see in example first sorting is done on school wise and if the school is same then percentageMarks wise.
The output printed on console is shown below.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Java | Collectors minBy(Comparator comparator) with Examples
- Java | Collectors maxBy(Comparator comparator) with Examples
- TreeMap comparator() method in Java with Examples
- SortedMap comparator() method in Java with Examples
- Comparator comparingDouble() method in Java with examples
- Comparator thenComparingLong() method in Java with examples
- Comparator naturalOrder() method in Java with examples
- Comparator reversed() method in Java with examples
- Comparator reverseOrder() method in Java with examples
- Comparator comparingLong() method in Java with examples
- Comparator thenComparingInt() method in Java with examples
- ConcurrentSkipListSet comparator() method in Java with Examples
- Comparator nullsFirst() method in Java with examples
- Comparator nullsLast() method in Java with examples
- Stream sorted (Comparator comparator) method in Java
- Comparator Interface in Java with Examples
- Comparator comparingInt() in Java with examples
- PriorityBlockingQueue comparator() method in Java
- TreeSet comparator() Method in Java
- PriorityQueue comparator() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.