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

How do listeners work?

617


What about main() method in java ?

655


public class Test { public static void main(String[] args) { int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; int countF = 0; int countG = 0; int countH = 0; int countI = 0; int countJ = 0; int countK = 0; int countL = 0; int countM = 0; int countN = 0; int countO = 0; int countP = 0; int countQ = 0; int countR = 0; int countS = 0; int countT = 0; int countU = 0; int countV = 0; int countW = 0; int countX = 0; int countY = 0; int countZ = 0; } } Can anybody tell me any alternate solution(like loop or something) to automate this initialization process. Ex:- for(char chr='A';chr<='Z'; chr++) { (int) String "count"+chr = 0; }

1941


What the difference is between execute, execute Query, execute Update?

450


What is bytecode verifier?

589






What is garbage collector?

725


What is a default constraint?

705


Explain yield() method in thread class ?

718


What is contractor means and methods?

654


What is enhanced loop in java?

626


what is the difference between preemptive scheduling and time slicing? : Java thread

630


What is the use of keywords in java?

647


Can anonymous class have constructor?

644


What is meant by 'Class access modifiers'?

663


What are the important features of Java 11 release?

677