• 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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: 66192
250
  • 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: 14347
237
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

 
What are you doing? You are supposed to be reading this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!