• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to increase the size of an array

 
liu hao
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1807
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was a thread the same as this last week.... you should do a search
 
liu hao
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. i usually don't have much time online now .......
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic