Implementing the Comparable interface in Java give the object a natural ordering, as in makes it Sortable. The comparable interface only has one method:
CompareTo only requires a output of negative integer, zero or positive integer representing less than, equals to, or greater than. Also be aware that if object returns a compareTo value of 0 (Equals to) it is not the same as calling equals on the object. For example new BigDecimal(“5.0”) and new BigDecimal(“5.00”) returns false on equals but 0 on compareTo!
When comparing multiple fields it is important to remember the order you compare them, start with the most significant fields! Below is a example of how to implement compareTo: