About 3,560 results
Open links in new tab
  1. ListIterator in Java - GeeksforGeeks

    Nov 1, 2022 · In Java, the listIterator() method of the LinkedList class returns a ListIterator that allows us to iterate over the elements of the list. Example: [GFGTABS] Java // Java Program to Demonstrate the // use of listIterator() in LinkedList import java.util.LinkedList; import java.util.ListIterator; pub

  2. Java ArrayList listIterator() Method - W3Schools

    Use a ListIterator to loop forward and backward through a list: cars.add("Volvo"); . cars.add("BMW"); . cars.add("Ford"); .

  3. Iterate through List in Java - GeeksforGeeks

    Jun 3, 2024 · Method 3: Using List iterator. 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. It is used to iterator over a list using while loop. Syntax: ListIterator<data_type> variable = list_name.listIterator(); Below is the example of this method: Java

  4. loops - Ways to iterate over a list in Java - Stack Overflow

    Given a List<E> list object, I know of the following ways to loop through all elements: // Not recommended (see below)! E element = list.get(i); // 1 - can call methods of element. // 2 - can use 'i' to make index-based calls to methods of list. // ...

  5. Iterate List in Java using Loops - GeeksforGeeks

    Jun 21, 2021 · There are various ways to iterate through a java List but here we will only be discussing our traversal using loops only. So, there were standard three traversals available so do three methods do exists but with the introduction of java 8 …

  6. Ways to Iterate Over a List in Java - Baeldung

    Apr 10, 2025 · In this article, we demonstrated the different ways to iterate over the elements of a list using the Java API. These options included the for loop, enhanced for loop, Iterator, ListIterator, and the forEach() method (included in Java 8). Then we learned how to use the forEach() method with Streams.

  7. ListIterator in Java with examples - BeginnersBook

    Sep 11, 2022 · In the last tutorial, we discussed Iterator in Java using which we can traverse a List or Set in forward direction. Here we will discuss ListIterator that allows us to traverse the list in both directions (forward and backward). In this example we are traversing an ArrayList in both the directions. names.add("Shyam"); . names.add("Rajat"); .

  8. Iterating over an ArrayList in Java - Java Guides

    In this guide, we covered various methods to iterate over an ArrayList in Java: Using For-Loop: Basic and flexible method. Using Enhanced For-Loop: Simplifies code and improves readability. Using Iterator: Allows element removal during iteration. Using ListIterator: Supports bidirectional traversal and modification of elements.

  9. How to Iterate List in Java - ConcretePage.com

    Jan 14, 2025 · We can convert List into Stream by calling List.stream() and then iterate using Stream.foreach method. List provides methods to convert it into Iterator, ListIterator and Spliterator and then we can iterate them. List can also be …

  10. 7 Ways to Iterate Over a List in Java: From Classic Loops to …

    Oct 8, 2024 · In this blog, we’ll explore 7 different ways to iterate over a list in Java, discussing when and why to use each one. 1. Using a for Loop (Traditional Method)

Refresh