need to confirm - ArrayList size()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javaalien
    New Member
    • May 2007
    • 34

    #1

    need to confirm - ArrayList size()

    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
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    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.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      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:[code=java]
      ArrayList(int initialCapacity )[/code]
      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

      Comment

      • javaalien
        New Member
        • May 2007
        • 34

        #4
        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:[code=java]
        ArrayList(int initialCapacity )[/code]
        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?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          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?
          Code:
          java -Xmx1024m YourApplication
          kind regards,

          Jos

          Comment

          Working...