Comparableinterface can be implemented by implementing only one method: compareTo. Implement the existing class by defining the the natural order of that class. compareTo() method compares the two object of same type and returns a numerical result based on the comparison. If the result is negative, then the object sorts less than the other; if 0, the two are equal, and if positive, this object sorts greater than the other. To translate this into boolean, simply performs object1.compareTo(object2) <op> object, where op is one of <, <=, =, !=, >, or >=.
public int compareTo( Object o );
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: February 16, 2005 If you enjoyed this post then why not add us on Google+? Add us to your Circles