Today I wanted to use the java code below and it did not work of course. I know that in order to process the idea below I should create a basic array which should include all my String variables but... I am wondering is there an option to change my code and process the code without the mentioned basic array ?
ArrayList<String> array = new ArrayList<String>();
String variable1 = "text1";
String variable2 = "text2";
String variable3 = "text3";
for ( int i = 1; i <= 3; i++ ){
array.add(i, variable + i ); // error
}
thank you in advance !
array.add("text1")?variable1,variable2, andvariable3should just be an array (variable[]). I see what you are trying to do withvariable+i, but it will not do what you are wanting. You want to use an array.