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


Please Help Members By Posting Answers For Below Questions

Why is it called buffering?

582


How are this() and super() used with constructors in java programming?

568


What are static initalizers in java ?

577


How can an object be unreferenced?

538


What is a boolean in java?

575






What is meant by call by reference?

505


What is a subsequence of a string?

543


Which is easier netbeans or eclipse?

608


What is difference between path and classpath in java?

483


Can we start a thread twice in java?

508


how we can make a write-only class in java?

558


What is thread count in java?

543


How do you achieve singleton?

529


Where can i get Latest SUN Certification Dumps and what are the Sun Certification Codes that are available, Im new to JAVA, so please gimme info as i need to write J2EE - Core Java Certification

1367


Write a program to reverse a number in java?

558