You can't do it the way you're trying to... But you can 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);
}
Answer from Chris on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
To access an element in the ArrayList, use the get() method and refer to the index number: ... Loop through the elements of an ArrayList with a for loop, and use the size() method to specify how many times the loop should run:
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit8-ArrayList › topic-8-3-arraylist-loops.html
8.3. Traversing ArrayLists with Loops — CS Java
Since for each loops do not use an index, you cannot do this special case of incrementing only if it is changed. So if you are going to add or remove items or you need the index, use a regular for loop or a while loop. ... 8-3-4: Assume that nums has been created as an ArrayList object and ...
🌐
Quora
quora.com › How-can-I-add-all-elements-of-an-arraylist-to-another-array-list-using-loop-It-is-for-homework-and-we-cant-use-the-addall-method
How can I add all elements of an arraylist to another array list using loop? It is for homework and we can't use the addall method.
Answer (1 of 3): To add to the target ArrayList you’re going to need to use the methods of that ArrayList, so presumably either [code ]ArrayList.add(E)[/code] or [code ]ArrayList.addAll(Collection )[/code] unless you’re using a subclass with some other method(s) available. Since you’r...
🌐
GeeksforGeeks
geeksforgeeks.org › java › iterating-arraylists-java
Iterating over ArrayLists in Java - GeeksforGeeks
import java.util.*; class GFG { ... numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8); // Iterating using for loop for (int i = 0; i < numbers.size(); i++) // Printing and display the elements in ArrayList System.out....
Published   January 19, 2026
🌐
Coderanch
coderanch.com › t › 606355 › java › Add-edit-ArrayList-elements-loop
Add & edit ArrayList elements from inside a for loop (Beginning Java forum at Coderanch)
Create a new StringBuilder (preferable to StringBuffer) before the start of the loop. Add each character to the StringBuilder. When you find the ., ? or !, add the StringBuilder to the ArrayList and then reinitialise your StringBuilder reference with a new StringBuilder.
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome › Unit7-ArrayList › topic-7-3-arraylist-loops.html
7.3. Traversing ArrayLists with Loops — CSAwesome v1
You can use a enhanced for loop ... in an ArrayList, just like you do with an array when you only care about the values in the list and not their indices. An example is shown in the main method below. Note however that you can’t use the enhanced for loop if you want to add or remove elements while traversing ...
🌐
Stanford
web.stanford.edu › class › archive › cs › cs108 › cs108.1082 › 106a-java-handouts › HO49ArrayList.pdf pdf
CS106A, Stanford Handout #49 Fall, 2004-05 Nick Parlante ArrayList
The prototype of add() is: public void add(Object element);. The type "Object" means that the argument can be any pointer type – String, or Color, or DRect. We will · study the Object type in more detail soon when we look at Java's "inheritance" features. For now, Object works as a generic ...
🌐
CopyProgramming
copyprogramming.com › howto › java-add-two-arraylist-element-using-for-loop
Adding ArrayList Elements Using For Loop: Complete 2026 Guide with Best Practices - Java add two arraylist element using for loop
November 18, 2025 - When using a regular for loop, you maintain full control over the iteration logic, including the ability to break early or skip elements based on conditions. The add() method appends elements to the end of the list by default, with O(1) average time complexity for insertion.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 33223467 › how-to-add-to-arraylist-in-a-for-loop › 33223849
java - How to add to ArrayList in a For loop - Stack Overflow
October 20, 2015 - As it is you are just declaring ... just do: public static ArrayList phoneList = new ArrayList() (if you are running older versions of java), otherwise use public static ArrayList phoneList = new ArrayList<>()....
🌐
Blogger
javarevisited.blogspot.com › 2012 › 03 › how-to-loop-arraylist-in-java-code.html
5 Ways to Loop or Iterate over ArrayList in Java?
The ListIterator also offers to add() method to add new elements in ArrayList while looping and most importantly you can traverse on both direction. It also allow you to modify the List like adding or removing element.
🌐
Baeldung
baeldung.com › home › java › java collections › adding elements to a collection during iteration
Adding Elements to a Collection During Iteration | Baeldung
June 27, 2025 - Now, let’s apply the enhanced for-loop approach to a list of integers, adding each number multiplied by 2: List<Integer> numbers = new ArrayList<>(List.of(1, 2, 3)); @Test public void givenList_whenAddElementWithEnhancedForLoopAndCopy_thenModifiedList() { List<Integer> copyOfNumbers = new ArrayList<>(numbers); for (int num : copyOfNumbers) { numbers.add(num * 2); } assertIterableEquals(Arrays.asList(1, 2, 3, 2, 4, 6), numbers); }
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-add-element-in-java-arraylist
How to Add Element in Java ArrayList? - GeeksforGeeks
July 23, 2025 - Element can be added in Java ArrayList using add() method of java.util.ArrayList class.
🌐
Stack Overflow
stackoverflow.com › questions › 30633861 › adding-elements-to-arraylist-using-a-loop
java - adding elements to arraylist using a loop - Stack Overflow
May 22, 2017 - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String name, capital; ArrayList<String> input = new ArrayList<>(); name = jTextField1.getText(); capital = jTextField2.getText(); for(int i=0;i < 10;i++) { input.add(name); input.add(capital); jTextArea4.setText(String.valueOf(input.get(input.size))); } ... I hope this will help you. ... this is wrong becuase the aaraylist contains 10 elements . even if you do thsi the textfield will print all the 10 elements. 2015-06-04T02:35:24.683Z+00:00 ... Completely remove the loop.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-loop-arraylist-in-java
How to loop ArrayList in Java
One of the easiest way to iterate through an ArrayList is by using for loop: import java.util.ArrayList; public class ArrayListExample { public static void main(String[] args) { ArrayList<String> names = new ArrayList<>(); names.add("Chaitanya"); names.add("Rahul"); names.add("Aditya"); // names.size() returns size of ArrayList and get() // method returns the element present at specified index for (int i = 0; i < names.size(); i++) { System.out.println(names.get(i)); } } }
🌐
LabEx
labex.io › tutorials › java-add-elements-to-array-and-arraylist-117386
Java - Add Elements to Array and ArrayList
import java.util.Arrays; public class ArrayInsert { public static int[] insertAtIndex(int[] arr, int elementToAdd, int index) { if (index > arr.length || index < 0) { throw new IndexOutOfBoundsException("Index is out of range!"); } else { int[] newArr = new int[arr.length + 1]; for (int i = 0, j = 0; i < arr.length; i++, j++) { if (i == index) { newArr[j++] = elementToAdd; } newArr[j] = arr[i]; } return newArr; } } public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5}; System.out.println("Initial Array: " + Arrays.toString(arr)); arr = insertAtIndex(arr, 6, 2); System.out.printl
🌐
Studytonight
studytonight.com › java-examples › add-elements-to-array-and-arraylist-in-java
Add Elements to Array and ArrayList in Java - Studytonight
August 19, 2021 - Append means to add to the end. We will first create a new array of larger size. Next, we will transfer the elements to this new array. Finally, we can add the new item at the end of this new array.