How to implement CompareTo method in Java
|Top Tutorials||New Tutorials||Submit||Login||Register|
Total Hits: 12749
Total Votes: 140 votes
Category: JAVA/Core JAVA
Submitted on: 2011-11-15 15:11:31
Submitted By: Javin Paul
Description:CompareTo method is defined in Comparable interface in Java and used to implement natural ordering of object.Implementing and overriding compareTo is neither too easy but not too difficult as well , there are certain things we need to keep in mind e.g. compareTo must be consistent with equals method, not using subtraction for comparing two integers etc. This article explains correct way of implementing compareTo in Java. More detail...