Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

arrays in java

 
Prasanna Govindan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
ary[index]=12
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.

Thanks
Prasanna
 
Thomas Drew
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Array are not to be dynamic. You should use an ArrayList or Vectors.
 
Victor Flores O'connor
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you mean like this???
'size' can be whatever you want at runtime

 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic