Difference between compare() & equals() with an example....
Comparator Interface
Collapse
X
-
Tags: None
-
Originally posted by dmjproIf you implement "first one", then it will be OK.
For details see API doc.
Debasis Jana.Comment
-
Originally posted by praveenkumarvpkI wnt d diffrence bet 'em....
method defines an 'order' of elements e1 < e2 < e3 ... en. If e1,compare(e2)
is less than zero then e1 < e2; if it returns greater than zero then e2.compare(e1)
returns less than zero so e2 < e1. Otherwise both are considered equal and then
e1.equals(e2) == e2.equals(e1) == true.
The compare() method imposes a 'stronger' relation between two objects than
the equals() method does.
kind regards,
JosComment
Comment