Knowledge Walls
John Peter
Pune, Maharashtra, India
Difference between string equals and object equals in JAVA?
sno String.equals() Object.equals()
1 Compares the value of two strings. Compares hashCode value of two objects. hashCode is a unique integer to access the memory. Same object represents same hashCode value. Find hashCode value by hashCode() method of Object class.
2 Both are returns boolean. It returns false when both string values are not equals otherwise true. Returns true if both objects are pointing same memory otherwise false.
3 String obj1 == String obj2. Compares the memory of the objects. If both objects are pointing same memory then it returns ture otherwise false. Object obj1 == Object obj2 - double equals(==) compares the reference of the objects. so if this both obj1 and obj2 are in same reference memory then it return true or false. same as Object.equals() method.

Previous Topics
Previous lessons of current book.
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details