*
The moose likes Beginning Java and the fly likes how to increase the size of an 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 "how to increase the size of an array" Watch "how to increase the size of an array" New topic
Author

how to increase the size of an array

liu hao
Greenhorn

Joined: Oct 02, 2009
Posts: 9
help, how to increase the size of an array to store more objects? we are supposed not to use Arraylist.

thanks for suggestion.
regards
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You can't change the size of an array. Create a new one and copy the data from the old one to the new one.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4164
    
  21

You can't. Arrays have a fixed size. There are alternatives though, like creating a new array with the intended size, then copying the content from the original array to the new one. There are also APIs which make this easier (see the Arrays and System javadocs. You might not want to use them, though, if this is an assignment.


Steve
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1659
    
  11

There was a thread the same as this last week.... you should do a search


When you do things right, people won't be sure you've done anything at all.
liu hao
Greenhorn

Joined: Oct 02, 2009
Posts: 9
thanks. i usually don't have much time online now .......
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Paul Clapham wrote:You can't change the size of an array. Create a new one and copy the data from the old one to the new one.


thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to increase the size of an array
 
Similar Threads
Increasing Array Size
size of array
applets
Increasing font size in Eclipse
Dynamically increasing array size