Java Stream: Sort by Multiple Fields With thenComparing()
Sort by multiple fields in a Java stream with comparing() and thenComparing(), mix ascending and descending order, handle nulls and pick keys at runtime.
Sort by multiple fields in a Java stream with comparing() and thenComparing(), mix ascending and descending order, handle nulls and pick keys at runtime.
Java Comparator interface with lambdas, comparing(), thenComparing(), reversed() and nullsFirst(), plus sorting by multiple fields in Java 25.
Learn the Java Comparable interface with compareTo() examples, the contract rules, the subtraction and equals() traps, and natural order in records.
Learn to compare float and double in Java with a relative tolerance, Double.compare(), NaN and -0.0 rules, float vs double precision and BigDecimal.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.