Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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?



In collection sorting comparable and comparator interface will be used..but why this two interfaces ..

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

Post New Answer

More Core Java Interview Questions

Explain about class in java?

0 Answers  


What is the difference between abstraction and encapsulation?

0 Answers  


What are the differences between string and stringbuffer?

0 Answers  


what is an objects lock and which objects have locks? : Java thread

0 Answers  


what are class,constructor and primitive data types?

2 Answers   IBM,


What is an abstract class and abstract method?

5 Answers  


What is java util hashmap?

0 Answers  


What is the difference between procedural and object-oriented programs?

0 Answers  


what invokes a threads run() method? : Java thread

0 Answers  


What is the exact difference in between Unicast and Multicast object ?

4 Answers   Accenture,


What is externalizable?

0 Answers  


What are drawbacks of singleton class?

0 Answers  


Categories