• Post Reply Bookmark Topic Watch Topic
  • New Topic

Size of ArrayList  RSS feed

 
victor kamat
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been told that an ArrayList is backed by an array.

The size of array is limited to Integer.MAXiMUM.

So is the number objects that an ArrayList can hold limited to Integer.MAXIMUM.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
victor kamat wrote:
So is the number objects that an ArrayList can hold limited to Integer.MAXIMUM.


Yep. Integer.MAX_VALUE is over 2 billion. If your objects were 8 bytes each, you'd need 16 billion bytes to hold them, and another 8 billion to hold the array itself; 24 GB to hold just these objects.

If you looped over the objects in your array, spending just ten clock cycles on each, it would take 5 seconds on a typical desktop machine.

This is really not much of a limitation.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

There are other implementation details, that will prevent you from instantiating an array that large. One is the size of an object. There is a max size of 2gb on an object -- hence, your array can't be bigger than 2gig (includes all the references, and header for the object).

Henry
 
Dmitry Mamonov
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you like to keep so much objects in memory same time?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A decent application uses a RDBMS for that. That's what they are for. Handling massive amount of data efficiently.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!