variable substitution

Hello, all

I am new to Java (and to this forum) but I do have a background in javascript. I am wondering if the following is possible in Java?

//////////////////////////////////////////////////

import static java.lang.System.out;

public class Demo

{

int num1, num2, num3;

public static void main (String [] args)

{

for (int i=1; i <= 3; i++)

{

num = i;

out.println(num);

{

}

}

/////////////////////////////////////////////

In this code, I want to be able to substitute the value of i in the for loop for the name of the variable, so that the first time through the loop the variable becomes num1 which gets a value of i and is printed, the 2nd time

through the loop it becomes num2 etc. I realize this is a simple example and could easily be done without this kind of substitution, but in other examples with more complicated code it would be useful.

I know this kind of variable substitution - I'm not even sure it's called variable substitution - can be done in javascript, but can it be done in java?

Thank you for any assistance.

nrdaddy

[1194 byte] By [nrdaddya] at [2007-11-27 11:14:22]
# 1

Can't be done. Closest equivalent: use an array, list or map:

http://java.sun.com/docs/books/tutorial/collections/index.html

BigDaddyLoveHandlesa at 2007-7-29 14:06:30 > top of Java-index,Java Essentials,Java Programming...
# 2

Why would you even WANT to do something like that? A simple array would work perfectly.

petes1234a at 2007-7-29 14:06:30 > top of Java-index,Java Essentials,Java Programming...
# 3

My usual advice for someone going from scripting to Java is to forget everything you thought you knew and start fresh. There's just too much nasty going on in scripting that has no place in proper programming.

BigDaddyLoveHandlesa at 2007-7-29 14:06:30 > top of Java-index,Java Essentials,Java Programming...