I know that ==
operator is applicable for content comparison for primitive types and reference comparison for objects.
Similarly, .equals()
method of object class is for reference comparison of objects and content comparison in strings and wrapper classes.
But the following points which I took from SCJP/OCJP notes, I am not able to understand. I looked on the web and find only the differences between ==
and .equals
but not the relation as how it is mentioned below.
- If
r1==r2
is true thenr1.equals(r2)
is always true. - If
r1==r2
is false thenr1.equals(r2)
may return true (or) false. - If
r1.equals(r2)
is true thenr1==r2
may return true (or) false. - If
r1.equals(r2)
is false thenr1==r2
is always false.