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 |
What is bool mean?
How to find the size of an array a)array.length() b)array.length c)array.size() d)array.size
how to crate clint-server socket?
1 Answers Accenture, Infosys, Infotech, TCS,
How can you write a loop indefinitely in java programming?
Is string is a class in java?
What is java basic concept?
Give a practical example of singleton class usage?
What is the immediate superclass of the Dialog class?
How does sublist works in java?
Program to Find the second largest element in an array.
what is request dispatcher and how does it work?
Why java does not supports multiple inheritance?