• 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

Confusion regarding hashCode() method of Object class

 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I have some queries:

a) What is a hashCode() of an object ? (is it the memory location at which it is stored?)

b) What is the significance of hashCodes with respect to how objects are stored in Collections?

~ Mansukh
 
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If only I had a dollar for every forum post about these questions!
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mansukhdeep Thind wrote:a) What is a hashCode() of an object ?


It is a numeric digest that helps to identify it.

(is it the memory location at which it is stored?)


No.

b) What is the significance of hashCodes with respect to how objects are stored in Collections?


1. They only have significance for hashed collections (eg, java.util.HashMap).
2. Their effectiveness, in such a context, is directly proportional to how good they are; and that's a bit of a black art. Effective Java has a very good Item on how to write a good hash which doesn't blind you with maths.

For a more general description, you may also find this article useful.

Winston
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Mansukhdeep Thind wrote:a) What is a hashCode() of an object ?


It is a numeric digest that helps to identify it.

(is it the memory location at which it is stored?)


No.

b) What is the significance of hashCodes with respect to how objects are stored in Collections?


1. They only have significance for hashed collections (eg, java.util.HashMap).
2. Their effectiveness, in such a context, is directly proportional to how good they are; and that's a bit of a black art. Effective Java has a very good Item on how to write a good hash which doesn't blind you with maths.

For a more general description, you may also find this article useful.

Winston



Thanks man..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic