Hi,
I am trying to add created objects to an ArrayList in a for-loop through indexes. The code below gives me errors when I try compile
//Create 4 Question objects... Question ques1 = new Question("First", 1); Question ques2 = new Question("First", 2); Question ques3 = new Question("First", 3); Question ques4 = new Question("First", 4); //Create an empty Question ArrayList ArrayList<Question> list = new ArrayList<Question>(); //for loop through 4 times starting at index 1 for(int i=1; i<=4; i++) { //Trying to add each Question object along with the specified index during the loop. list.add(ques+i); }
The code outputs: cannot find symbol: variable ques
Could anyone identify the problem?
Thanks