naming variables in code

H

helena

can i call variables from code interactivly...for examle:
i have variables variable1,variable2,variable3,variable4.can i call them
from a loop : for(i=1;i<5;i++){variablei}

an array is not a solution because i need more complex sufixes like
04101, where very nomber means something.

thank you fror youre answer,helena
 
A

Andrey Kuznetsov

can i call variables from code interactivly...for examle:
i have variables variable1,variable2,variable3,variable4.can i call them
from a loop : for(i=1;i<5;i++){variablei}
no

an array is not a solution because i need more complex sufixes like 04101,
where very nomber means something.
use Hashtable with suffixe as key
 
G

Gusbin

why not use a map collection (java.util.map), where your key is the
number/string that id's the variable, and the vallue is an object type
from an interface that has some common methods that u can use to
extract the information.
 
A

Andrey Kuznetsov

can i call variables from code interactivly...for examle:
How can you call a variable at all? Consider:

int i = 5;
call(i); // nonsense
if you would read what I wrote you could see that I answered "no".

What you can is - put some Object into Hashtable using some key and retrieve
it:
Instead of
int a04101 = 100;

you write:
Hashatble ht = new Hashtable();
String s = "a04101";
Integer value = new Integer(100);
ht.put(key, value);
 
A

Ann

Andrey Kuznetsov said:
if you would read what I wrote you could see that I answered "no".

What you can is - put some Object into Hashtable using some key and retrieve
it:
Instead of
int a04101 = 100;

you write:
Hashatble ht = new Hashtable();
String s = "a04101";
Integer value = new Integer(100);
ht.put(key, value);

Sorry, I was referring to the OP; I should have been more clear.
Still, how do you CALL a variable?
 
C

Collin VanDyck

How can you call a variable at all? Consider:
int i = 5;
call(i); // nonsense

The meaning of his question was clearly obvious. Must you stretch to
find trivial things to complain about whenever possible?

As to the OP's question, yes a HashMap or something similar would fit
your need as Andrey pointed out.

Collin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top