File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 JavaScript Promises Essentials this week in the JavaScript 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the difference between Comparator and Comparable