Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

What is the contract of hashCode() and equals() methods in Java?

Pragya Keshap answered on February 4, 2023 Popularity 5/10 Helpfulness 2/10

Contents


More Related Answers

  • java override equals and hashcode
  • java hashcode
  • how to hash string in java
  • java hashcode
  • java hashcode
  • object comparison using Hashcode and equals methods
  • what happens if hashcode and equals contract voilated
  • What is the importance of hashCode() and equals() methods
  • write java code to demonstrate the implementation of the hashing.

  • What is the contract of hashCode() and equals() methods in Java?

    0

    Contract of hashCode() and equals() methods is as follows in Java:

    If object1.equals(object2), then object1.hashCode() ==

    object2.hashCode() should always be true. It means if two objects

    are equal then their hashCode should be same.

    If object1.hashCode() == object2.hashCode() is true, it does not

    guarantee that object1.equals(object2). It means if two objects have

    same hashCode, then can still have different values so that may not

    be equal objects

    https://www.tutorialspoint.com/what-is-the-contract-between-equals-and-hashcode-methods-in-java#:~:text=General%20contract%20associated%20with%20hashCode()%20method&text=If%20two%20objects%20are%20equal,value%20for%20both%20the%20objects.

    Popularity 5/10 Helpfulness 2/10 Language java
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 04 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10

    Closely Related Answers



    0
    Popularity 5/10 Helpfulness 1/10 Language java
    Tags: java methods
    Link to this answer
    Share Copy Link
    Contributed on Feb 28 2024
    Aswin Sundar
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.