Описание тега comparator
A Common interface to create an object that specifies the way of comparing other objects. When using this tag on implementation heavy questions - tag the code language the implementation is written in.
A Common interface to create an object that specifies the way of comparing other objects.
Generally, the sorting algorithm takes two parameters - two objects which should be compared. The comparison is then performed between the two objects:
- A negative return value indicating the first object is smaller than the second in the sorted order.
- A zero return value indicating the two objects are equal in the sorted order.
- A positive value indicating the first object is larger than the second in the sorted order.
Java and other languages define the ability to separate sorting algorithms from the specific comparison used.
In Java, for instance, one of the mechanisms is to define an object that implements the Comparator
interface. This object can then be used as an argument when calling sorting methods.
See also: