This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What is the difference between Comparator and Comparable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the difference between Comparator and Comparable" Watch "What is the difference between Comparator and Comparable" New topic
Author

What is the difference between Comparator and Comparable

Hemant Agarwal
Ranch Hand

Joined: Nov 21, 2005
Posts: 138
What is the difference between Comparator and Comparable?
Renato Losio
Ranch Hand

Joined: Nov 23, 2005
Posts: 99
A detailed explanation (with examples) on
ONJava

Extract from the article:

Implementing the Comparable interface enables you to define one way to compare instances of your class. However, objects are sometimes comparable in many ways. For example, two Person objects may need to be compared by age or by last/first name. In cases like this, create a Comparator that defines how to compare two objects. To make objects comparable in two ways, then you need two comparators.


Renato Losio - www.arsenio.it - renatoweb@arsenio.it
Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
U can get the details from here
 
Don't get me started about those stupid light bulbs.
 
subject: What is the difference between Comparator and Comparable
 
It's not a secret anymore!