Difference between equals operator == and equals() method

For comparison of two variable for their equality Java offers two methods. Equals operator ==, and equals() method in Object class. Since both of them checks the equality of L.H.S. and R.H.S. then what is the difference between them? Difference lies in the definition The difference lies in the definition of the operator and the method. The definition of == says that the operator compares the value inside the variable available on both sides. And the definition of the equals() method changes as per the implementation in the corresponding class. To understand the difference take a scenario of String objects. We have three String variables viz. s1, s2 and s3. String s1 = "hello"; String s2 = "hello"; String s3 = new String("hello"); Based on the above initialization, what would…
Read More