In collection sorting comparable and comparator interface will be used..but why this two interfaces required..two will work same purpose so why there are two interfaces instead of one?when to use comparator and when to use comparable?
Answer / obi
In order to implement an interface (such as Comparable) you need access to rewrite a specific class.
If a certain class is given to you as a 'black box' and you now need some way to use a written sort on it - notice that its a black box thus you cannot rewrite any of its code - you would have to create a new class which would act as a Comparator.
| Is This Answer Correct ? | 6 Yes | 0 No |
How will you load a specific locale?
Why destructor is not used in java?
What is mean by UML? what is the use? where we are using?
What is Generic in java? Where can we write Generic ( class or method or objects or etc...)? with simple example? Thanks, Bose.
2 Answers Infosys, Tech Mahindra,
Is it compulsory to have atleast one abstract method in abstract class?
Difference between Interface & Abstract class?
strings in java are objects.why?
What is treeset in java collection?
What is the importance of main method in Java?
Explain the scope or life time of class variables or static variables?
How to find the length and capacity of a string buffer ?
why use interface? if interface declear a method implement in class. why direct implement method in class