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 lambda expressions build a multi-field Comparator?ComputerScienceOne · Java 8: Lambda Expressions
- How can method references and Comparator methods make ordering more concise?ComputerScienceOne · Java 8: Lambda Expressions
- How can a Comparator sort Student objects by GPA?ComputerScienceOne · Searching
- How can you sort lists and arrays of students in Java?ComputerScienceOne · Handling javanull values
- How can comparator functions order Student structures?ComputerScienceOne · Comparator Functions
- How does a Comparator determine the order of two elements?ComputerScienceOne · Comparators
- What is the difference between Comparable and Comparator in Java?ComputerScienceOne · Comparators
- How does Java sort arrays and lists with comparators?ComputerScienceOne · Sorted Collections