• Post Reply Bookmark Topic Watch Topic
  • New Topic

maximum number of element a HashMap can hold  RSS feed

 
Bharat Makwana
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Just looking for the confirmation from experts here. I went through many threads regarding hashmap max capacity. Some people says it depends on memory as hashmap can grow
dynamically. I have one double, if I am not wrong hashmap internally uses array to hold it's elements and array size is in int, and maximum size of int in java is 2^31-1. So the max capacity of hash map is also 2^31-1 isn't it ??!!

Please clear the double ?

Thanks,
Bharat
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the maximum number of buckets. Each bucket uses a form of linked list which has no limitation except memory. So in theory a HashMap can hold an unlimited number of elements. In practice you won't even get to 2^30 because you will have run out of memory long before that.
 
Bharat Makwana
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply Rob Prime !

Got my answer. Thanks.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!