Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

how to use iterator in java

// Java code to illustrate the use of iterator
import java.io.*;
import java.util.*;
  
class Test {
    public static void main(String[] args)
    {
        ArrayList<String> list = new ArrayList<String>();
  
        list.add("A");
        list.add("B");
        list.add("C");
        list.add("D");
        list.add("E");
  
        // Iterator to traverse the list
        Iterator iterator = list.iterator();
  
        System.out.println("List elements : ");
  
        while (iterator.hasNext())
            System.out.print(iterator.next() + " ");
  
        System.out.println();
    }
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #iterator #java
ADD COMMENT
Topic
Name
2+7 =