aspose file tools*
The moose likes Beginning Java and the fly likes Confusion regarding hashCode() method of Object class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Confusion regarding hashCode() method of Object class" Watch "Confusion regarding hashCode() method of Object class" New topic
Author

Confusion regarding hashCode() method of Object class

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

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

~ Mansukh
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
If only I had a dollar for every forum post about these questions!
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

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

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

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..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Confusion regarding hashCode() method of Object class