Concept
How can Comparator order Student objects by different fields?
ComputerScienceOne / Comparators
"Comparators can define several orderings for Student objects based on one or more member variables. A comparator named byName orders students by last name and then first name: if the last names are equal, it compares the first names; otherwise, it compares the last names. A byNameDesc comparator reverses those comparisons to order last names and first names in descending, Z-to-A order. A byId comparator orders Student objects by ID in ascending order by returning a.getId().compareTo(b.getId()). The source also introduces a comparator that orders Student objects by GPA in descending order."
Related Ideas
- How can comparator functions order Student structures?ComputerScienceOne · Comparator Functions
- How does a Comparator determine the order of two elements?ComputerScienceOne · Comparators
- How can a Comparator sort Student objects by GPA?ComputerScienceOne · Searching
- What is a comparator function and how does it determine element order?ComputerScienceOne · Comparator Functions
- What is the difference between Comparable and Comparator in Java?ComputerScienceOne · Comparators