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 we can declare a static variable?
What are the drawbacks of singleton class?
What is += mean in java?
Differentiate between stringbuffer and string?
different types of threads?
How do you use find and replace?
How many bits is a string?
What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?
What is the use join() in Threads ?
Have you used any version control ? if so explain about it?
Difference between Linked list and Queue?
What is the diff. b/w Interfaces & Abstract class?