Search the courses, subjects, tracks, games and features, or jump straight to a page.
4 cards from this section. Quick, good the night before a test.
What is the purpose of the Comparator interface in Java?
Think about when you'd need to sort items differently.
What method do you need to implement in a Comparator?
What are the two objects you compare?
What does the Comparator interface allow you to do?
Think about what flexibility you need beyond natural ordering.
True or False: A Comparator can only sort objects in increasing order.
Consider how you could reverse the sorting order.
Create a Comparator for a class that represents products in a store. The Comparator should first compare products by price, and then by name if prices are the same.
Think about the significance of each attribute when comparing.
Imagine you have a data structure that needs to sort student records by GPA, and if two students have the same GPA, by last names. Design your solution using the Comparator interface.
What condition checks will you need?
6 more questions in this section. Enroll free to practise them all.
Enroll free