Exforsys
+ Reply to Thread
Results 1 to 5 of 5

Difference between hashcode() and equals()...

This is a discussion on Difference between hashcode() and equals()... within the Java forums, part of the Programming Talk category; I have tried so many times to find the difference...but not getting a satisfactory explanation.... can anybody explain with a ...

  1. #1
    singhsn is offline Junior Member Array
    Join Date
    Sep 2007
    Answers
    3

    Difference between hashcode() and equals()...

    I have tried so many times to find the difference...but not getting a satisfactory explanation.... can anybody explain with a good example??


  2. #2
    sampra is offline Junior Member Array
    Join Date
    Mar 2008
    Location
    bangalore
    Answers
    9
    hashcode is an integer number which is provide to each object by jvm note that this is not address of object but for convencing internally they use

    equals() is used to compare the objects it returns boolean value
    if any doubt then pls ask


  3. #3
    Bijay29 is offline Junior Member Array
    Join Date
    Jan 2009
    Answers
    2
    Compares values for equality. Because this method is defined in the Object class, from which all other classes are derived, it's automatically defined for every class. However, it doesn't perform an intelligent comparison for most classes unless the class overrides it. It has been defined in a meaningful way for most Java core classes. If it's not defined for a (user) class, it behaves the same as ==.
    It turns out that defining equals() isn't trivial; in fact it's moderately hard to get it right, especially in the case of subclasses.


  4. #4
    jack705 is offline Junior Member Array
    Join Date
    Mar 2010
    Answers
    18
    I think Java will be able to resolve between the two objects using their equals() method


  5. #5
    Sudheer Kethavarapu is offline Junior Member Array
    Join Date
    May 2011
    Answers
    5
    equals() the name itself is pretty explanatory.
    coming to hashcode() , this is a special code given to every object created. the neccesity in giving this code is, in c / c++ we can trace the addres of any variable by using "&" operator. The virus programs are developed with the help of address values, to avoid such things hashcode was introduced , hashcode() it retruns a value which is not the addres value but a unique number assigned to every object.

    there is no need of comparision between equals() and hashcode() , they r distinct to each other



    ur's
    sudheer


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...