Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

hashCode()????

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does the method hashCode do? can u give some sample code about hashCode()?
thnks....
raymond
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It simply returns an integer that can be used as a hash code for that particular object, which can be used by the Java collection classes such as Hashtable.
Moreover, it is required that if objects are equal according to the equals(Object obj) method, the hash code returned by them must be same.
As for examples, in standard Java wrapper class Integer, if you construct an object of class Integer such as -
Integer seven = new Integer(7);
and call seven.hashCode() it will return 7.
You can read about how to implement hashCode() method in your own classses at - http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf
HTH,
- Manish
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic