I have an arraylist where I want to add elements via a for loop.
Answer answer1;
Answer answer2;
Answer answer3;
ArrayList answers = new Array
If you simply need a list, you could use:
List<Answer> answers = Arrays.asList(answer1, answer2, answer3);
If you specifically require an ArrayList
, you could use:
ArrayList<Answer> answers = new ArrayList(Arrays.asList(answer1, answer2, answer3));
You can't do it the way you're trying to... can you perhaps do something like this:
List<Answer> answers = new ArrayList<Answer>();
for(int i=0; i < 4; i++){
Answer temp = new Answer();
//do whatever initialization you need here
answers.add(temp);
}