This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Diferents between Comparable and Comparator Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Diferents between Comparable and Comparator Interfaces" Watch "Diferents between Comparable and Comparator Interfaces" New topic
Author

Diferents between Comparable and Comparator Interfaces

Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

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

Joined: Aug 31, 2004
Posts: 11343

"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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

marc i got it! thankz
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

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.


Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Diferents between Comparable and Comparator Interfaces
 
Similar Threads
Diff. Between Comparable & Comparator Interface
Interface Comparator
Comparator vs. Comparable
comparator and comparable interfaces
Comparable and Comparator