Tutorials Shared by the Internet Community
|Top Tutorials||New Tutorials||Submit||Login||Register|
Tutorial Basic Detail
Total Hits: 10458
Total Votes: 139 votes
Average Rating: 2.81 out of 5
Category: JAVA/Core JAVA
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.