UrbanPro
true

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Comparable vs Comparator

Vivek R.
20/11/2017 0 0
java.lang.Comparable java.util.Comparator
  1. For comparing some other object with its own object. Ex. I am comparing myself to some other employee.
  2. Method signature is: 
    int compareTo (T object).
  3. For implementing Comparable, access to the original class is required.
  4. The class itself needs to implement Comparable and hence it is inside java.lang package.
  5. It can be used to provide single way of sorting.
  1. For comparing two objects by a separate class. Ex. Manager is comparing two employees with each other.
  2. Method signature is:
    int compare (T object1, T object2).
  3. If the required class is not accessible i.e., present inside some jar, then a Comparator implementation can be used that just accepts the two objects and do the comparison.
  4. It is a utility that can be used by an external class to perform the required action and hence it is inside java.util package.
  5. It can be used to provide multiple sorting ways like NameComparator, SalaryComparator etc.
0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

Design Pattern
Prototype Design Pattern: Ø Prototype pattern refers to creating duplicate object while keeping performance in mind. Ø This pattern involves implementing a prototype interface which tells...

Priority in TestNG
public class Priority { @Test (priority=1)public void login() {System.out.println("login");} @Testpublic void email1() {System.out.println("email1");} @Test (priority=-2)public void email2() {System.out.println("email2");} //I...
S

Sarthak C.

0 0
0

Java Interview Questions & Answers
Java Interview Questions have been designed especially to get you acquainted with the nature of questions you may encounter during your interview for the subject of Java Programming Language. As per my...

On the Job training is always best
On the job training always provides an opportunity to learn the best industry practices. While you work on real time you would encounter many challenges that will force you to learn many new things. Class...
M

X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more