• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Dynamically increasing array size

 
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.
 
author
Posts: 23834
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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 ]
     
    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.
     
    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 ]
     
    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
    Boost this thread!