File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Increasing Array size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Increasing Array size " Watch "Increasing Array size " New topic

Increasing Array size

rajesh kumar rayavarapu

Joined: May 16, 2007
Posts: 12
Hi, iam new to the java.
How to increase the array size dynamically?

means if i take arry[3]={0,1,2} and then i want insert 3 in the same arry.Please send to me i have faced this question in one of the interview.

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

you can't. once an array is declared, its size is fixed.

you have the option of declaring a new array, copying over all the values, and re-assigning the reference, however.

or you could use an arraylist instead.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Increasing Array size
It's not a secret anymore!