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
Is null keyword in java?
What are the different access modifiers available in java?
can java object be locked down for exclusive use by a given thread? Or what happens when a thread cannot acquire a lock on an object? : Java thread
What does exclamation mean in java?
What is the exact difference in between Unicast and Multicast object?
What is time complexity algorithm?
What does void * mean?
What are selection structures?
What is a null check?
What are the supported platforms by java programming language?
Class c implements interface I containing method m1 and m2 declarations. Class c has provided implementation for method m2. Can I create an object of class c?
Difference between java and javascript
Explain about the interpreter in java?
Explain about OOPS concepts and fundamentals.
What methodology can be employed to locate substrings inside a string?