Diff between Comparator and Comparable?

Answer Posted / rajesh

Comparable interface uses Object's compareTo() to compare
the objects. We have to override the compareTo() method in
order to sort.

Where as Comparator, checks for compare() method. You can
sort based on particular property of the object.

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between import java.util.date and java .util?

555


What is a generic data type?

564


What is a parameter in a function?

522


What language is java written?

525


Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?

583






What are the advantages and disadvantages of object cloning?

566


What are actual parameters?

514


Are functions objects in java?

535


What is update method called?

653


Are floats faster than doubles?

555


What is an exception in java?

637


Can we declare a constructor as final?

669


How can we break singleton in java?

514


Define linked list and its features with signature?

532


How do you avoid global variables?

532