wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 24183

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
It is sorta covered in the JavaRanch Style Guide.
subject: Changing size of java array
Similar Threads
Anonymous array
Random number between size of an array
just check this...
about this array class