Win a copy of AWS Security 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Doubt on the working and performance of HashMap.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I have some confusion with respect to the working of Hashmap.

What is know about the working of a hashmap is that when a hashmap is created a array of linked list is created i.e. each element that is added to the hashmap the hashcode is calculated of the key object that hashcode is the index in the array at which the element would be added to the linked list.

My doubt here is that suppose i have some code where i am adding 2 objets to a hashmap one hashmap returns returns the hashcode 1 and the element will be added to the linked list at index - 1. Now if i am adding another element whose hashcode returned is suppose INT.max_value or very large number so will the array of linked list be of size this much (INT.max_value or very large number) ??
 
Marshal
Posts: 69517
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
I am afraid you have posted in the wrong location. I am sure Henry who moderates this forum won’t mind if I move your post somewhere more appropriate.
The array in a HashMap defaults to 16 length; this discussion is about how the hash codes are converted to array indices. If you need to know any more, be sure to ask.
 
Marshal
Posts: 15639
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, EaseUp (←click on the link). Putting "Urgent" in your subject line does not usually get it the kind of attention you want. We're all volunteers here and if anyone wants to reply, they will reply in their own time. I have edited the subject and removed "Urgent".
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Now if i am adding another element whose hashcode returned is suppose INT.max_value or very large number so will the array of linked list be of size this much (INT.max_value or very large number) ??



You have the wrong idea, hashcodes are just the start of getting the index. You should study the ACTUAL code in HashMap instead of speculating. One of the great things about Java is that the standard library code is published. Here for example is HashMap put method:



Use the Source!

Bill

 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic