Connecting Tech Pros Worldwide Help | Site Map

need to confirm - ArrayList size()

Member
 
Join Date: May 2007
Posts: 34
#1: May 27 '07
Guys, what is the max size for ArrayList size()?
I have arraylist with size up to 4 000 000, is there any problem with it...
my application's running so slow when my arraylist size up to 2 000 000.
Please confirm with me..
Thank you.
sicarie's Avatar
Moderator
 
Join Date: Nov 2006
Location: USA
Posts: 3,929
#2: May 27 '07

re: need to confirm - ArrayList size()


I would imagine it is limited by your heap size, which, in turn, is constrained by your system - how much RAM you have, how much you have allocated to the JVM, etc... There are ways to increase your heap size from the normal setting (I forget what that is off the top of my head, but you can google it), but you might end up needing to add more RAM to the system.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#3: May 27 '07

re: need to confirm - ArrayList size()


Quote:

Originally Posted by javaalien

Guys, what is the max size for ArrayList size()?
I have arraylist with size up to 4 000 000, is there any problem with it...
my application's running so slow when my arraylist size up to 2 000 000.
Please confirm with me..
Thank you.

The theoretical maximum number of elements in an ArrayList is 2^31-1 but
memory constraints lower that nuber significantly. First assure that you are
able to store 4 million elements by passing the flag -Xmx<value> to the JVM
to allow it do increate the size of the heap to <value> (1024m would be fine)

Note that the ArrayList class has a nice constructor:
Expand|Select|Wrap|Line Numbers
  1. ArrayList(int initialCapacity)
Set the value of initialCapacity to 4,000,000. This sets up an (empty) ArrayList
that can potentially contain that many elements without the need to reallocate
room for all the elements.

kind regards,

Jos
Member
 
Join Date: May 2007
Posts: 34
#4: May 27 '07

re: need to confirm - ArrayList size()


Quote:

Originally Posted by JosAH

The theoretical maximum number of elements in an ArrayList is 2^31-1 but
memory constraints lower that nuber significantly. First assure that you are
able to store 4 million elements by passing the flag -Xmx<value> to the JVM
to allow it do increate the size of the heap to <value> (1024m would be fine)

Note that the ArrayList class has a nice constructor:

Expand|Select|Wrap|Line Numbers
  1. ArrayList(int initialCapacity)
Set the value of initialCapacity to 4,000,000. This sets up an (empty) ArrayList
that can potentially contain that many elements without the need to reallocate
room for all the elements.

kind regards,

Jos

How to do that please?
I have tried this - java -Xmx1024m, but comes out all the usage..
Do I have to do this first and then only run my application?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#5: May 27 '07

re: need to confirm - ArrayList size()


Quote:

Originally Posted by javaalien

How to do that please?
I have tried this - java -Xmx1024m, but comes out all the usage..
Do I have to do this first and then only run my application?

Expand|Select|Wrap|Line Numbers
  1. java -Xmx1024m YourApplication
kind regards,

Jos
Reply