This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Changing size of java array Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Changing size of java array" Watch "Changing size of java array" New topic
Author

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
Marshal

Joined: Jul 08, 2003
Posts: 24054
    
  13

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: http://aspose.com/file-tools
 
subject: Changing size of java array
 
Similar Threads
just check this...
about this array class
NullPointerException
Anonymous array
Random number between size of an array