| 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
|
 |
 |
|
|
subject: Diferents between Comparable and Comparator Interfaces
|
|
|