Search the courses, subjects, tracks, games and features, or jump straight to a page.
2 cards from this section. Quick, good the night before a test.
What method must a class implement to be Comparable?
Think about the method name and its purpose.
What does the compare method in a Comparator return?
Recall the three possible outcomes of comparisons.
Which interface is used for defining the natural ordering of a class?
Think about the interface that modifies the object itself.
True or False: A Comparator can be used to define multiple sorting criteria.
Reflect on what you need if you want to compare in different ways.
Create a Student class and implement both Comparable and a Comparator that sorts by name and marks.
Think of how you would structure the class and implement the two interfaces.
Consider a scenario where you have a list of employees that you want to sort first by department and then by salary. How would you implement this?
Remember that you can chain comparators together for multiple sorting criteria.
5 more questions in this section. Enroll free to practise them all.
Enroll free