This documentation is archived and is not being maintained.

List.iterator Method

Visual Studio 2005

Provides an iterator to iterate over a List object.

Package: java.util

Assembly: vjslib (in vjslib.dll)

public abstract java.util.Iterator iterator();

An iterator that can be used over the List object.

In this example, you create an initialize a collection and then you retrieve an iterator to iterate over the collection and display its members.

// list-iterator1.jsl
// List.iterator example

import java.util.*;

public class MyClass
   public static void main()
      Collection hSet = new HashSet();

      // Add some elements to the HashSet:
      hSet.add("1 ");
      hSet.add("2 ");
      hSet.add("3 ");
      hSet.add("4 ");

      // Retrieve an iterator to the hashset:
      Iterator iter = hSet.iterator();
      // Extract elements from iterator.
      // Note that the elements may not follow the order in which they
      // are added to HashSet.
3 1 4 2