• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically increasing array size

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi alll
Can anybody tell me how we can declare an array and increase its size dynamically.....
i.e the no of elements to be put in an array can be determined at runtime.
 
Henry Wong
author
Marshal
Pie
Posts: 21420
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Parameswaran Thangavel:
hi alll
Can anybody tell me how we can declare an array and increase its size dynamically.....
i.e the no of elements to be put in an array can be determined at runtime.


Once an array object is instantiated, it's size it fixed -- it can't be increased dynamically. You have two options...

  • You can instantiate another array and copy the elements to the new array.
  • Use a collection class instead.


  • Henry
    [ June 30, 2006: Message edited by: Henry Wong ]
     
    David O'Meara
    Rancher
    Posts: 13459
    Android Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    2a: use a Collections class then use toArray() to convert to an array at the fast moment before returning.
     
    Rue Fi
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    What about using Vectors?
    [ July 09, 2006: Message edited by: Rue Fi ]
     
    Tony Morris
    Ranch Hand
    Posts: 1608
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    An array is fixed size, List is poorly designed, net.tmorris.adt.sequence.Sequence fixes it all.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic