If you have an ArrayList (with a name alin this case), and you want to get the first five elements of the list as variables, you can do this:
String x1 = al.get(0);
String x2 = al.get(1);
String x3 = al.get(2);
String x4 = al.get(3);
String x5 = al.get(4);
However, using a for loop, is there a way to do something like this:
for (int i = 1; i < 6; i++){
String namer = "x" + i.toString();
String [value of String 'namer'] = al.get(i-1);
}
Or is there a completely different method that is much more efficient?
user4607619
source
share