• Post Reply Bookmark Topic Watch Topic
  • New Topic

Diferents between Comparable and Comparator Interfaces  RSS feed

 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

Can someome explain me the very diferencias between Comparable and Comparator Interfaces.

I know that the Comparable Interface needs to implements the method:
->int compareTo(T o)

And Iknow too that the Comparator Interface needs to implements the method:
->int compare(T o1, T o2)

But I want to know more the very diferencias.

Very thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Comparable" is an adjective. If an object is Comparable, it has the ability to compare itself to some other object.

"Comparator" is a noun. A Comparator is an object with the ability to compare 2 other objects to each other.
[ January 23, 2008: Message edited by: marc weber ]
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
marc i got it! thankz
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Comparator interface has to be implemented by the class ,Object of which you want to compare with Other Objects.

But Comparator interface can be implemented by any class and give you power to
compare any two Objects.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!