Java Comparator

Contributor(s): Matthew Haughn

Java Comparator is an interface for sorting Java objects. Invoked by “java.util.comparator,” Java Comparator compares two Java objects in a “compare(Object 01, Object 02)” format.

Using configurable methods, Java Comparator can compare objects to return an integer based on a positive, equal or negative comparison. Since it is not limited to comparing numbers, this can allow Java Comparator to be set up to order lists alphabetically or numerically. With, Java comparator can also be used to successfully order serialized data structures.

Java Comparator is similar to the Comparable interface but is intended for defining alternate sort orders where Comparable sorts by natural ordering such as lexicographic sorting.

This was last updated in July 2016

Continue Reading About Java Comparator

Dig Deeper on Java Development Tools

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.


File Extensions and File Formats