Geting a variable from a String

Hi, i need to get a variable from a string. For example:

..............

int test1;

int test2;

int test3;

.........

int test = getvariablefromstring("test"+3);

..................

[383 byte] By [Comp-Freaka] at [2007-11-27 10:10:19]
# 1
Check out the Reflection API. Or check out the Reflection tutorial: http://java.sun.com/docs/books/tutorial/
camickra at 2007-7-13 0:47:03 > top of Java-index,Java Essentials,Java Programming...
# 2

Reflection will work for member variables, not locals. It'sprobably not the right solution for you though.

If you just want test1, test2, test3, ... testN, then you want an array or a List.

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html

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

jverda at 2007-7-13 0:47:03 > top of Java-index,Java Essentials,Java Programming...