• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the capacity of a Map

 
Rohit Ahuja
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i store as many as 20000 objects in a Map?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure you can. The capacity is only limited by the amount of memory available to JVM. And though only references are stored in the map, the objects exist on the heap. So, the number of objects you can store depends on how much memory each object is consuming.
 
Rohit Ahuja
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
I know how to use the Map interface but what i am worried about is whether it is a good idea to store 20000 elements in a Map???
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Deepak A:
Michael,
I know how to use the Map interface but what i am worried about is whether it is a good idea to store 20000 elements in a Map???


You didn't ask if it was a good idea, though -- you asked if you can. Different question! But the answer is the same: yes, pretty much. 20,000 is a small number as far as any of the standard API map implementations go.

On another note, you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. An initial isn't enough for a last name. You can change your display name here. Thanks! We take this rule rather seriously.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a good idea to store 20,000 items in a map, that depends on what you're storing in the map. If you're just storing relatively small objects, it's not a problem. If you're storing large objects, you could get out of memory problems.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic