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 Difference between Comparable and Comparator? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between Comparable and Comparator?" Watch "Difference between Comparable and Comparator?" New topic
Author

Difference between Comparable and Comparator?

mansi gupte
Ranch Hand

Joined: Dec 30, 2008
Posts: 72
Can anyone explain the difference between these two?? with an example?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38031
    
  22
Have you read the API documentation? Here, and here.

Comparable "lives inside the class" and says "I differ from other objects of the same class and I can tell you the difference."
Comparator "lives outside the class" and says "I can find out which objects differ in this respect."
You can use several Comparators on the same class.
mansi gupte
Ranch Hand

Joined: Dec 30, 2008
Posts: 72
Campbell Ritchie wrote:Have you read the API documentation? Here, and here.

Comparable "lives inside the class" and says "I differ from other objects of the same class and I can tell you the difference."
Comparator "lives outside the class" and says "I can find out which objects differ in this respect."
You can use several Comparators on the same class.


hey ,
thanks for the prompt reply.i will take this one as a reference to understand better.

PS:I read the API Doc , but got ,more confused due to the verbosity.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38031
    
  22
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Comparable and Comparator?
 
Similar Threads
difference RAD & WSAD
Difference between wsad5.1.2 & Rad
Synchonized
JATO Vs JDOM
Run as AWT or SWT Application Eclipse Question