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 does the Comparable interface require to be implemented?
Think about how one object might compare itself to another.
What is the purpose of the Comparator interface?
Consider scenarios where you might want different sorting criteria.
What does the Comparable interface provide?
Focus on the primary role of the Comparable interface.
True or False: The Comparator interface can only be used for natural ordering.
Consider the different functionalities of Comparable and Comparator.
Write a Java class that implements Comparable and gives a natural ordering based on two attributes - age and name.
Think about the logic needed to handle the two comparisons together.
Implement a Comparator for a class that represents a book with attributes for title and publish year. Sort it first by year, then by title if years are the same.
You’ll need to use two comparisons in your Comparator to account for both criteria.
5 more questions in this section. Enroll free to practise them all.
Enroll free