Course Content

  • TreeMapDemo
  • NameComparator
  • ComparatorDemo

Course Content


Comparator denotes a component that can compare two objects and sort them using Java's sorting capability. You can pass a Java Comparator to the sorting method when sorting a Java List, for example. During sorting, the Comparator is used to compare the objects in the List.

When two voltages are compared, a comparator circuit outputs a 1 (the voltage on the positive side; VDD in the example) or a 0 (the voltage on the negative side) to indicate which is larger. Comparators are frequently used to check whether an input has achieved a predefined value, for example.

A user-defined class's objects are ordered using the Java Comparator interface. This interface is part of the util package in Java, and it has two methods: compare(Object obj1,Object obj2) and equals (Object element).

In Java, a Comparable object compares itself to another object, but a Comparator object compares multiple objects of different kinds. In Java, Comparable provides the compareTo() method for sorting elements, whereas Comparator gives the compare() function.

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
Apple App Store
598K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
15K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere