Better use a library like Guava:

import com.google.common.collect.Lists;

Iterator<Element> myIterator = ... //some iterator
List<Element> myList = Lists.newArrayList(myIterator);

Another Guava example:

ImmutableList.copyOf(myIterator);

or Apache Commons Collections:

import org.apache.commons.collections.IteratorUtils;

Iterator<Element> myIterator = ...//some iterator

List<Element> myList = IteratorUtils.toList(myIterator);       
Answer from Renaud on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java list › converting iterator to list
Converting Iterator to List | Baeldung
June 27, 2025 - The Apache Commons Collections library provides options to work on a List. We’ll use IteratorUtils to do the conversion:
🌐
W3Schools
w3schools.com › java › java_iterator.asp
Java Iterator
Java Examples Java Videos Java ... Java Study Plan Java Interview Q&A ... An Iterator is an object that can be used to loop through collections, like ArrayList and HashSet....
🌐
W3Schools
w3schools.com › java › ref_arraylist_iterator.asp
Java ArrayList iterator() Method
import java.util.ArrayList; import ... while(it.hasNext()) { System.out.println(it.next()); } } } ... The iterator() method returns an Iterator for the list....
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ListIterator.html
ListIterator (Java Platform SE 8 )
July 21, 2026 - Java™ Platform Standard Ed. 8 ... An iterator for lists that allows the programmer to traverse the list in either direction, modify the list during iteration, and obtain the iterator's current position in the list. A ListIterator has no current element; its cursor position always lies between ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › listiterator-in-java
ListIterator in Java - GeeksforGeeks
ListIterator is an advanced cursor in Java used to traverse elements of List implementations. It extends the Iterator interface and was introduced in Java 1.2.
Published: April 10, 2026
🌐
GeeksforGeeks
geeksforgeeks.org › java › iterate-through-list-in-java
Iterate through List in Java - GeeksforGeeks
July 23, 2025 - ListIterator is an iterator in Java which is available since the 1.2 version. It allows us to iterate elements one-by-one from a List implemented object.
🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-an-iterator-to-a-list-in-java
Convert an Iterator to a List in Java - GeeksforGeeks
September 2, 2026 - An Iterator is used to traverse elements of a collection one by one. Java does not provide a direct Iterator-to-List conversion method, but we can easily create a List by consuming the elements of the Iterator.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › ListIterator.html
ListIterator (Java Platform SE 7 )
Java™ Platform Standard Ed. 7 ... An iterator for lists that allows the programmer to traverse the list in either direction, modify the list during iteration, and obtain the iterator's current position in the list. A ListIterator has no current element; its cursor position always lies between ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-listiterator
Java ListIterator - ListIterator in Java | DigitalOcean
August 4, 2022 - It is available since Java 1.2. It extends Iterator interface. It is useful only for List implemented classes. Unlike Iterator, It supports all four operations: CRUD (CREATE, READ, UPDATE and DELETE). Unlike Iterator, It supports both Forward Direction and Backward Direction iterations. It is a Bi-directional Iterator. It has no current element; its cursor position always lies between the element that would be returned by a call to previous() and the element that would be returned by a call to next().
Top answer
1 of 13
337

The three forms of looping are nearly identical. The enhanced for loop:

for (E element : list) {
    . . .
}

is, according to the Java Language Specification, identical in effect to the explicit use of an iterator with a traditional for loop. In the third case, you can only modify the list contents by removing the current element and, then, only if you do it through the remove method of the iterator itself. With index-based iteration, you are free to modify the list in any way. However, adding or removing elements that come before the current index risks having your loop skipping elements or processing the same element multiple times; you need to adjust the loop index properly when you make such changes.

In all cases, element is a reference to the actual list element. None of the iteration methods makes a copy of anything in the list. Changes to the internal state of element will always be seen in the internal state of the corresponding element on the list.

Essentially, there are only two ways to iterate over a list: by using an index or by using an iterator. The enhanced for loop is just a syntactic shortcut introduced in Java 5 to avoid the tedium of explicitly defining an iterator. For both styles, you can come up with essentially trivial variations using for, while or do while blocks, but they all boil down to the same thing (or, rather, two things).

EDIT: As @iX3 points out in a comment, you can use a ListIterator to set the current element of a list as you are iterating. You would need to use List#listIterator() instead of List#iterator() to initialize the loop variable (which, obviously, would have to be declared a ListIterator rather than an Iterator).

2 of 13
55

Example of each kind listed in the question:

ListIterationExample.java

import java.util.*;

public class ListIterationExample {

     public static void main(String []args){
        List<Integer> numbers = new ArrayList<Integer>();

        // populates list with initial values
        for (Integer i : Arrays.asList(0,1,2,3,4,5,6,7))
            numbers.add(i);
        printList(numbers);         // 0,1,2,3,4,5,6,7

        // replaces each element with twice its value
        for (int index=0; index < numbers.size(); index++) {
            numbers.set(index, numbers.get(index)*2); 
        }
        printList(numbers);         // 0,2,4,6,8,10,12,14

        // does nothing because list is not being changed
        for (Integer number : numbers) {
            number++; // number = new Integer(number+1);
        }
        printList(numbers);         // 0,2,4,6,8,10,12,14  

        // same as above -- just different syntax
        for (Iterator<Integer> iter = numbers.iterator(); iter.hasNext(); ) {
            Integer number = iter.next();
            number++;
        }
        printList(numbers);         // 0,2,4,6,8,10,12,14

        // ListIterator<?> provides an "add" method to insert elements
        // between the current element and the cursor
        for (ListIterator<Integer> iter = numbers.listIterator(); iter.hasNext(); ) {
            Integer number = iter.next();
            iter.add(number+1);     // insert a number right before this
        }
        printList(numbers);         // 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

        // Iterator<?> provides a "remove" method to delete elements
        // between the current element and the cursor
        for (Iterator<Integer> iter = numbers.iterator(); iter.hasNext(); ) {
            Integer number = iter.next();
            if (number % 2 == 0)    // if number is even 
                iter.remove();      // remove it from the collection
        }
        printList(numbers);         // 1,3,5,7,9,11,13,15

        // ListIterator<?> provides a "set" method to replace elements
        for (ListIterator<Integer> iter = numbers.listIterator(); iter.hasNext(); ) {
            Integer number = iter.next();
            iter.set(number/2);     // divide each element by 2
        }
        printList(numbers);         // 0,1,2,3,4,5,6,7
     }

     public static void printList(List<Integer> numbers) {
        StringBuilder sb = new StringBuilder();
        for (Integer number : numbers) {
            sb.append(number);
            sb.append(",");
        }
        sb.deleteCharAt(sb.length()-1); // remove trailing comma
        System.out.println(sb.toString());
     }
}
🌐
W3Schools
w3schools.com › java › ref_arraylist_listiterator.asp
Java ArrayList listIterator() Method
The listIterator() method returns a ListIterator for the list. To learn how to use iterators, see our Java Iterator tutorial.
🌐
Baeldung
baeldung.com › home › java › java list › ways to iterate over a list in java
Ways to Iterate Over a List in Java | Baeldung
June 27, 2025 - An Iterator is a design pattern that offers us a standard interface to traverse a data structure without having to worry about the internal representation. This way of traversing data structures offers many advantages, among which we can emphasize that our code doesn’t depend on the implementation. Therefore, the structure can be a binary tree or a doubly linked list, since the Iterator abstracts us from the way of performing the traversal. In this way, we can easily replace data structures in our code without unpleasant problems. In Java, the Iterator pattern is reflected in the java.util.Iterator class.
🌐
TutorialsPoint
tutorialspoint.com › convert-an-iterator-to-a-list-in-java
Convert an Iterator to a List in Java
May 12, 2025 - In this method, we will use a while loop to iterate over the Iterator and add each element to a new List. We will use the method hasNext() to check if there are more elements in the Iterator.
🌐
DataCamp
datacamp.com › doc › java › iterator
Java Iterator
It should be called after hasNext() to ensure that there is a next element. ... remove(): Removes the last element returned by the next() method from the underlying collection. This method is optional and may throw UnsupportedOperationException if the collection does not support removal. ... import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class IteratorExample { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Apple"); list.add("Banana"); list.add("Cherry"); Iterator<String> iterator = list.iterator(); while (iterator.hasNext()) { String fruit = iterator.next(); System.out.println(fruit); } } }
🌐
BeginnersBook
beginnersbook.com › 2014 › 06 › listiterator-in-java-with-examples
ListIterator in Java with examples
import java.util.ArrayList; import java.util.List; import java.util.ListIterator; public class ListIteratorExample { public static void main(String a[]){ ListIterator<String> litr = null; List<String> names = new ArrayList<String>(); names.add("Shyam"); names.add("Rajat"); names.add("Paul"); names.add("Tom"); names.add("Kate"); //Obtaining list iterator litr=names.listIterator(); System.out.println("Traversing the list in forward direction:"); while(litr.hasNext()){ System.out.println(litr.next()); } System.out.println("\nTraversing the list in backward direction:"); while(litr.hasPrevious()){ System.out.println(litr.previous()); } } }
🌐
Tutorialspoint
tutorialspoint.com › java › java_using_iterator.htm
Java - How to Use Iterator?
An iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list and the modification of elements.
🌐
Blogger
javarevisited.blogspot.com › 2011 › 10 › java-iterator-tutorial-example-list.html
How to use Iterator and ListIterator in Java? Example Tutorial
ListIterator doesn’t keep the current index and its current position is determined by a call to next() or previous() based on the direction of traversing. 1) Iterator in Java support generics so always use the Generic version of Iterator rather than using Iterator with raw type.