• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

equals() and hashCode()

 
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between equals() and hashCode() methods of the Object class?
When do we need to use hashCode() method ?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
equals() method is used to compare two objects.
i think hashCode() method will return the unique
key [ im not sure about hascode]
regards
o. subramaniam
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If objectA.equals(objectB) returns true, objectA.hashCode() must equal objectB.hashCode(). Use equals() when you want to test equality because hashCode() is not gaurenteed to be unique for every value, because it's clearer, and because it will perform better.
The hashCode() method exists to be used by data structures such as HashMap. A HashMap will allow very quick insertion and querying of entries, but it relies on the assumption that the values of hashCode() are reasonably varied. Look up hashtables for more information about the specifics.
reply
    Bookmark Topic Watch Topic
  • New Topic