• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Comparable and Comparator?

 
mansi gupte
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain the difference between these two?? with an example?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic