• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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: 362
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?
 
It was the best of times. It was the worst of times. It was a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic