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:
Discussions

java - How to add to ArrayList in a For loop - Stack Overflow
I have a sequence of information being randomly generated. I would like to save that information in a variable of some kind so that it can be recalled elsewhere. i think I want to use an ArrayList,... More on stackoverflow.com
🌐 stackoverflow.com
October 20, 2015
java - adding elements to an ArrayList using a loop and outputting them on console - Stack Overflow
I know this is a basic question but I've been struggling with with for many days and cannot find a solution. Please, any advice would be very sincerely appreciated. I'm simply trying to add ele... More on stackoverflow.com
🌐 stackoverflow.com
How to fill out an ArrayList with for each loop? (Java) - Stack Overflow
I have to fill in an ArrayList with the first 10 multiples of two using a for each loop. I really can't seem to figure out how and I can't use any other loops. Here is my code which is not working... More on stackoverflow.com
🌐 stackoverflow.com
Is there a way to add elements to an Array List all at once?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
6
1
November 2, 2021
🌐
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
🌐
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 ...
🌐
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.
🌐
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.
Find elsewhere
🌐
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 ...
🌐
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.
🌐
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<>()....
🌐
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.
🌐
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)); } } }
🌐
Vultr Docs
docs.vultr.com › java › examples › iterate-over-an-arraylist
Java Program to Iterate over an ArrayList | Vultr Docs
November 25, 2024 - Create an ArrayList and add some elements to it. Use a for loop to iterate through the ArrayList by index. ... import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<String> colors = new ArrayList<>(); ...
🌐
javaspring
javaspring.net › blog › java-arraylist-for-loop
Mastering Java ArrayList For Loops — javaspring.net
Iterating Over Elements: Use a for loop to perform operations on each element in the ArrayList, such as printing, modifying, or filtering. Searching for an Element: Use a for loop to search for a specific element in the list.