Search Interview Questions
| More than 3000 questions in repository.|
There are more than 900 unanswered questions.
Click here and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
|Core Java - Interview Questions and Answers for 'Equals vs hascode' - 1 question(s) found - Order By Newest|
|Ans. "equals" is the method of object class which is supposed to be overridden to check object equality. x.equals(y) means the references x and y are holding objects that are equal with the equality defined by the definition of equals method.|
Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements. This bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to and if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not.
|Help us improve. Please let us know the company, where you were asked this question :|
|Like Discuss Correct / Improve  equals  hascode  equals vs hascode|
|Which String class does not override the equals() and hashCode() methods, inheriting them directly from class Object?|
|Write a class and override the equals and hashcode method ?|
|How many threads can access a concurrent hashmap when the hashcode is overridden and always returns a zero.|
|What is the use of defining equals , compareTo and hashcode methods in a class ? Where are they used ?|