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 Changing size of java array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Changing size of java array" Watch "Changing size of java array" New topic

Changing size of java array

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
I have an array of Strings . Can i change its size at run time.
Is there a method for this?
john smith
Ranch Hand

Joined: Mar 04, 2004
Posts: 75
No. Array size is fixed at the point of creation. Should you need a list-type collection which can grow, use ArrayList instead.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

While John's answer is technically correct, you can of course allocate a new array and copy the old one over:

This is often all you really need, and it's actually how ArrayList works internally.

[Jess in Action][AskingGoodQuestions]
Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
thank you so much.
that was great help
I agree. Here's the link:
subject: Changing size of java array
It's not a secret anymore!