File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how hashCode() is used in HashMap? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how hashCode() is used in HashMap?" Watch "how hashCode() is used in HashMap?" New topic
Author

how hashCode() is used in HashMap?

ramu ta
Greenhorn

Joined: Feb 06, 2011
Posts: 18
how hashCode() is used in HashMap?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Check Jesper's post here.


[My Blog]
All roads lead to JavaRanch
ramu ta
Greenhorn

Joined: Feb 06, 2011
Posts: 18
thnak you, i understood the usage of hashCode() in HashSet.

but i want to know the usage of hashCode() in HashMap.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The concept is the same. The hashCode is used to identify in which bucket the object will be place in.
ramu ta
Greenhorn

Joined: Feb 06, 2011
Posts: 18
in HashSet, we can pass the searching object to the constructor of Hashset.
so the construtor is calling hashcode() method of searching object and going to the specific bucket for applying equals() method on those specific limited objects. this is clear to me...

but in HashMap.. we should pass key to get value... how this process is going? i m in confusion, will you please clear it?
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

veda kakarla wrote:......but in HashMap.. we should pass key to get value... how this process is going? i m in confusion, will you please clear it?

In a HashMap, essentially all the keys are stored in a Set. So, the same concept as for Set applies here too. When you ask for a value by giving the key, hashCode() and equals() shall be used to identify the bucket in which the key is in. Once the key is located, the value can be retrieved in no time.


OCPJP 6
ramu ta
Greenhorn

Joined: Feb 06, 2011
Posts: 18
thank you so much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how hashCode() is used in HashMap?