File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
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: 24166
    
  30

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
Anonymous array
about this array class
NullPointerException
just check this...
Random number between size of an array