• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array?  RSS feed

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can Array grow dynamically?if yes, how can we do that?
thanks.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. Once you instantiate an array the VM allocates space for it and there is no way to make it grow. You can create a temporary larger array, copy the contents of the old array into it and then set the old reference to the new array. Like this:

[ June 18, 2003: Message edited by: Michael Morris ]
 
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need a dynamically growing Array, thenArrayList is usually the class to use.
- Peter
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!