Answer the question
In order to leave comments, you need to log in
How to create a variable from an array?
In general, for example, we have some kind of array (ArrayList):
ArrayList<String> list = new ArrayList<String>();
list.add("x");
list.add("y");
for(String i : list) {
this.i = "This is "+i;
}
System.out.println(x+" "+y);
locals()['x']='Это х'
print x
Answer the question
In order to leave comments, you need to log in
Your desire is very similar to using map. Those. you just need to convert list to map. You will even get a bonus in the form of using characters forbidden in ordinary life in the names of "variables".
Map<String, String> tables_sql = new HashMap<>();
for( String role : new String[]{"cv_administrators+!;", "cv_operators", "cv_translators"}){
tables_sql.put(role, "This is role "+role);
}
// получение значения:
String val = tables_sql.get( "cv_administrators+!;" ); // This is role cv_administrators+!;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question