Skip to content

Glossary: Data Structures and Algorithms in Java

Comparable

Also written: compareTo, Comparable<T>

An interface for types that can compare themselves, through `compareTo`, which returns negative, zero or positive. `<T extends Comparable<T>>` lets one method such as `mergeSort` work for any such type, and a `Comparable` record such as `Delivery` can go in a `PriorityQueue` without a separate comparator.

Where the book teaches it

Related terms

comparatorPriorityQueuemerge sortnatural order