• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How much can go into a single array list element?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He's giving us the slip! Quick! Grab this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic