• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing size of java array

 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an array of Strings . Can i change its size at run time.
Is there a method for this?
 
john smith
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much.
that was great help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic