Comparing Long Values Using Collections.sort()

Date: 2025-04-18
This article details various methods for sorting collections of Long values in Java using Collections.sort()
and custom Comparator
implementations. It covers ascending and descending order, null handling (using nullsFirst()
and nullsLast()
), and multi-criteria sorting using thenComparing()
. The examples demonstrate efficient sorting techniques, including leveraging Java 8's enhancements to the Comparator
interface for cleaner code. The article uses a practical example of sorting a list of Employee objects based on their salaries to illustrate these concepts.
Read more: https://www.javacodegeeks.com/java-compare-long-collections-sort-example.html
Subscribe to my newsletter
Read articles from Yatin B. directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
