| Author |
Dynamically name arrays
|
KTSAIC Thomas
Greenhorn
Joined: Jul 08, 2005
Posts: 1
|
|
Hey all, Strange one for you... I have a table which will contain generic columns like so: PARAM0_NAME PARAM0_TYPE PARAM0_VALUE PARAM1_NAME PARAM1_TYPE PARAM1_VALUE 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
Rancher
Joined: Mar 22, 2000
Posts: 12266
|
|
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. Bill
|
Java Resources at www.wbrogden.com
|
 |
Nathan Pruett
Bartender
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)
|
-Nate
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. HTH Layne
|
Java API Documentation
The Java Tutorial
|
 |
 |
|
|
subject: Dynamically name arrays
|
|
|