CompareTo() method in Java must be compatible with equals method in Java i.e. if two objects are equal via equals method compareTo method must return “0″ for them, failing this may result in some subtle bug when you store those objects in collection class like arraylist in java.
compareTo method in Java must be compatible with equals method in Java i.e. if two objects are equal via equals method compareTo method must return “0” for them, failing this may result in some subtle bug when you store those objects in collection class like arraylist in java.
Liked By
Write Answer
Why equals() method must be compatible with compareTo in java ?
Join MindStick Community
You have need login or register for voting of answers or question.
Hubert Jason
17-Oct-2016I think this link will clear the things
http://www.leepoint.net/data/expressions/22compareobjects.html
Abhishek Maheshwari
13-Oct-2016Anonymous User
02-Sep-2015