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 Posted / 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 |
Post New Answer View All Answers
Why is the main method static?
Can you pass functions in java?
What is polymorphism and what are the types of it?
What is e java?
What is the difference between normal report & matrix report?
What does provide mean construction?
What are the two parts of a conditional statement?
What is * argv?
What is abstract class? Explain
What is the independent variable in an experiment?
Explain the access modifiers for a class, method and variables?
When will you define a method as static in Java?
Which is faster string or stringbuilder?
Is an object null?
What's the base class of all exception classes?