Back

Comparator

Idealogic’s Glossary

Comparator – is a tool for entering the conventions for ordering/sorting some objects or values in data structures. Comparators in Java is used for sorting the Objects in collections and are used very frequently in array, priority queues, search trees and other algorithms and operations that use comparison operators.

In the comparison method, the comparator functions as a specific method or function where two are passed as arguments and one returns is the relation between the two. It determines the nature of change of elements.

Some sorters are flexible and allow developers to define a custom comparator to support a specific comparison work. This capability can sort arrays with respect to one or many attributes or properties of objects in the array; flexibility.