• 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

Can an array have an indefinte size?

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Am using a dynamic array. Can this dy namoc array grow to hold any number of integers? Or is there a limit that Java places on it?
The error am getting is :
java.lang.ArrayIndexOutOfBoundsException
Can some brief me on this?
Thanks.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can change an array reference to access an array object of any size, but an array object has a fixed size. ArrayIndexOutOfBounds means that you are trying to access past the end of an array object.

If you posted code, perhaps we could figure out what you are doing and where it should be fixed...

-Nate
 
Avin Sinanan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks , I would like to post the code. But its like 2000 lines of code.
If it is still ok. Let me know, and I'll post it up.
Thanks for the help by the way.
yours respectfully Avin Sinanan
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did you mean by dynamic array? an array created at run time? using
new Type[not_compile_time_constant_int_expression_] ?
java arrays always have a fixed size. what you need is a List implementation, like java.util.ArrayList or java.util.Vector.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use ArrayList or Vector, you must also wrap your int values as Integer values. By using ArrayList (or Vector) the size of your array is not fixed it will grow as you add. With an array you must allocate a larger array and then copy to it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic