javacodex.com
Java Examples
Java Examples
memu home questions

Read Elements From An ArrayList Using An Iterator

This java example shows how to read all elements of an ArrayList using an Iterator.

Source: (ArrayListIterator.java)

import java.util.*;
 
public class ArrayListIterator { 
   public static void main(String[] args) { 
      ArrayList list = new ArrayList();
      list.add("John");
      list.add("Ringo");
      list.add("George");
      list.add("Paul");
 
      Iterator<String> it = list.iterator();
      while(it.hasNext()) {
         System.out.println(it.next());
      }
   } 
}
 

Output:

# java ArrayListIterator 
John
Ringo
George
Paul

Contact: javacodex@yahoo.com