aspose 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
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: 40052
    
  28
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: 40052
    
  28
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Comparable and Comparator?