Chapter 18: Problem 29
What is a comparator? What interface must it implement?
Short Answer
Expert verified
**Answer:** A Comparator is an interface in Java, used for custom sorting of objects in a collection. It belongs to the java.util package. When implementing the Comparator interface, a class must implement the `compare(T o1, T o2)` method, which takes two objects of type T as parameters and returns a negative integer if o1 should be placed before o2, a positive integer if o1 should be placed after o2, and 0 if o1 and o2 are considered equal in the sorted order.
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.