• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array?  RSS feed

 
Brian Smith
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.
 
Michael Morris
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 ]
 
Peter den Haan
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!