It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes arrays in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "arrays in java" Watch "arrays in java" New topic

arrays in java

Prasanna Govindan

Joined: Aug 21, 2005
Posts: 2
hi java Gurus,
Please some help....

i want to create an array whose size is determined at runtime
i dont want to give the dimensions of the array at declaration.
for eg:
int [] ary;
int index=0;
gives Null pointer exception.

Is there any way to declare an array and not mention the size of it and insert values into it...faciliating the size to be determined at runtime.

Thomas Drew
Ranch Hand

Joined: Sep 15, 2004
Posts: 47
Array are not to be dynamic. You should use an ArrayList or Vectors.
Victor Flores O'connor

Joined: Aug 05, 2005
Posts: 2
you mean like this???
'size' can be whatever you want at runtime

I agree. Here's the link:
subject: arrays in java
It's not a secret anymore!