File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Dynamically name arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Dynamically name arrays" Watch "Dynamically name arrays" New topic

Dynamically name arrays


Joined: Jul 08, 2005
Posts: 1
Hey all,

Strange one for you...

I have a table which will contain generic columns like so:


etc, etc...up to 9. What I would like to do is dynamically create the arrays for each of these columns at runtime, something like:

int i = 0;

while ( i < 10; i++ ){
String[] strParam<i>_name = new String[noReccount]
String[] strParam<i>_type = new String[noReccount]
String[] strParam<i>_value = new String[noReccount]

Any thoughts on whether this is feasible? I guess I just don't want to have to type it all out (I'm being lazy!)
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13024
If you want a variable number of String[] that can be located by names made up on the fly, I suggest you look into the "collections" API in the java.util package. Specifically the various Map implementations.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Why use Strings? Wouldn't it be better to make a small Parameter class with name, value, and type properties and create arrays of those?

(Warning - the following code hasn't been tested/compiled/anything - it's just out of my head, and is to serve as a general outline of the process...

I don't see anything specific to JSPs in this question... moving to Java Programming in General (Intermediate)

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I agree. You should create a class with fields that correspond to the columns in your table. Then you just have to manage a single array with instances of this class.



Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Dynamically name arrays
jQuery in Action, 3rd edition