Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes What is the capacity of a Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the capacity of a Map" Watch "What is the capacity of a Map" New topic
Author

What is the capacity of a Map

Rohit Ahuja
Ranch Hand

Joined: Oct 04, 2001
Posts: 121
Can i store as many as 20000 objects in a Map?


Face Off.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

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.


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Rohit Ahuja
Ranch Hand

Joined: Oct 04, 2001
Posts: 121
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the capacity of a Map