• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can an array have an indefinte size?

 
Avin Sinanan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • 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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Zakaria Haque
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!