• Post Reply Bookmark Topic Watch Topic
  • New Topic

How much can go into a single array list element?  RSS feed

 
Charles Mulloy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like the title says. If I put an object like a string, int, long, or even a custom object into an array list how big can it be without it returning an error? I'm not asking about the maximum size of the list but the individual element(s) going into the list. I know that a string object can't be larger than 2 or 4 GB but i'm not sure if objects in an array list have special restrictions on them.
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There aren't any such restrictions.

If you were thinking that there might be problems with putting "large" objects into an ArrayList, there can't be any such problems because you don't put objects into an ArrayList. You put references to objects into ArrayLists.
 
Charles Mulloy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused now. I thought I was actually putting things into the list. And get(int index) returns the object at the index and not the String equivalent, right?
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrong. You're not putting objects into the list, but references to these objects. Likewise, the get method returns a reference to the stored element. As such, the only size limitation of an ArrayList is the number of elements it can store, which is theoretically Integer.MAX_VALUE (2^31-1). In practice, the available memory determines the limit.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!