Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me what is the exact difference between == and .equals() in Java? As per my understanding == is test for same memory allocation whereas .equals() helps to compare between values?

1 Answer

0 votes
by (26.7k points)

Yes, .equals() helps you to compare what is over the code and nothing more. Also, .equals() helps you to override the closest parent class where the overridden method is present. Whereas, == helps you to return true only when both the variables are redirected to the same object. So, for == you are applying it to object equality.

I hope this will help.

Want to become a Java Expert? Join Java Course now!!

Want to know more about Java? Watch this video on Java Tutorial | Java Course:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...