I have a string containing the variable name. I want to get the value of that variable.
int temp = 10;
String temp_name = "temp";
Is it possible to access the value 10 by using temp_name?
I have a string containing the variable name. I want to get the value of that variable.
int temp = 10;
String temp_name = "temp";
Is it possible to access the value 10 by using temp_name?
I suggest that you use a Map<String, Integer> instead:
Create the map by doing
Map<String, Integer> values = new HashMap<String, Integer>();
Then change
int temp = 10;
to
values.put("temp", 10);
and access the value using
int tempVal = values.get(temp_name);