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 |
Explain tree set and its features?
What is a line separator in java?
What is the difference between add() and addElement() method in Vector Class ?
how do I create a runnable with inheritance? : Java thread
JVM is platform independent or depeneded?
Can a class declared as private be accessed outside it’s package?
why would you use a synchronized block vs. Synchronized method? : Java thread
What is unsigned char?
Explain what pure virtual function is?
What are the supported platforms by java programming language?
What are the differences between checked exception and unchecked exception?
What is an eror in java?