• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Creating multiple arrays at run time?

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. Im having difficulty of handling arrays that was created at run time. How will i give unique variable name for each array created?

Thanks for the help!
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

You can't, but you don't need to. Variable names are never created at runtime; they're just a compile-time concept. If you need to create an unknown number of objects at runtime, then normally what you'd do is keep them either in an array, or better, a Collection class like ArrayList.



After this, list.get(0) is one of the arrays, list.get(1) is another, etc, up to list.get(9).
 
john von
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that quick response. Actually, im saving to a Vector an object referrences to a multidimensional array:



The contents of multiple array "dist[][]" is most likely has different value for each loop. How would i get the values of each in a vector? Or is it the proper way to do it?

Thank you again!

[ June 10, 2004: Message edited by: john von ]
[ June 10, 2004: Message edited by: john von ]
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vectors have indices.
Vector v = new Vector();
v.add("Hi");
v.add("There");
v.get(0); // gets "Hi"
v.get(1); // gets "There"
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
by pressing list.get(0) i am getting the only first element in the first array.
how can I access the entire array like 1st array, 2nd array like that
Thanks in advance!
 
Bartender
Posts: 370
44
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there, welcome to the Ranch!

This thread is 17 years old, would you like to create a new topic and give more details about what you are trying to do?
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic