LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   difference between Java compare and compareTo methods (https://www.linuxquestions.org/questions/programming-9/difference-between-java-compare-and-compareto-methods-232410/)

kpachopoulos 09-19-2004 03:59 AM

difference between Java compare and compareTo methods
 
Does anybody know the differences between Java compare method (implements Comparator interface) and Java compareTo method (implements interface Comparable)?
The only obvious difference, which i have understood, is that that "compare" uses 2 arguments, while "compareTo" uses 1 argument.

mirradric 09-19-2004 04:03 AM

precisely.
A comparable is an object which knows can can compare itself with other objects.
A comparator compares two other objects which need not know how to compare themselves with other objects.

mirradric 09-19-2004 04:08 AM

or should i say an instance of


All times are GMT -5. The time now is 06:37 PM.