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
What is compareto?
What technique can be employed to compare two strings?
Why is the main method declared static?
What is a subsequence of a string?
Why is sizeof not a function?
What is a copy constructor in java?
What is a Presistent Object?
What is memory leak and how does java handle it?
What is arraylist e?
What is method in java with example?
hr interview how many minutes asking question
difference between byte stream class and character stream class?
What are aggregate functions explain with examples?
What is return data type?
a thread is runnable, how does that work? : Java thread