Comparators

A Comparator is a software mechanism that defines how objects are ordered — it tells us whether A < B, A = B, or A > B.

# java.util package

public int compare(Object o1, Object o2)

Returns:

The actual numeric value doesn’t matter (only the sign does).

Total Order Relation Properties

For all a, b, c in set S:

Priority Queue

A Priority Queue is like a queue, but each item has a priority. Only the “highest-priority” (lowest key) element can be removed first.