Share via


ListIterator Class

The ListIterator class is used to iterate over the elements in a list.

Syntax

class ListIterator extends Object

Run On

Called

Methods

  Method Description
Gg921812.pubmethod(en-us,AX.60).gif begin Moves the iterator to the start of the list.
Gg921812.pubmethod(en-us,AX.60).gif cancelTimeOut Cancels a previous method call to the setTimeOut method. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif definitionString Returns a textual representation of the type of the iterator.
Gg921812.pubmethod(en-us,AX.60).gif delete Removes the element that is pointed to by the iterator from the list.
Gg921812.pubmethod(en-us,AX.60).gif end Moves the iterator past the last element in the list.
Gg921812.pubmethod(en-us,AX.60).gif equal Determines whether the specified object is equal to the current one. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif getTimeOutTimerHandle Returns the timer handle for the object. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif handle Retrieves the handle of the class of the object. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif insert Inserts a new value at the position in the list that the iterator currently points to.
Gg921812.pubmethod(en-us,AX.60).gif more Determines whether the list iterator points to a valid element.
Gg921812.pubmethod(en-us,AX.60).gif new Creates a new iterator for a particular list. (Overrides the new Method.)
Gg921812.pubmethod(en-us,AX.60).gif next Moves the iterator to the next element in the list.
Gg921812.pubmethod(en-us,AX.60).gif notify Releases the hold on an object that has called the wait method on this object. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif notifyAll Releases a lock on the object that was issued by the wait method on this object. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif objectOnServer Determines whether the object is on a server. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif owner Returns the instance that owns the object. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif setTimeOut Sets up the scheduled execution of a specified method. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif toString Returns a textual representation of the current list value that is pointed to by the iterator. (Overrides the toString Method.)
Gg921812.pubmethod(en-us,AX.60).gif usageCount Returns the current number of references, that is, the value of the reference counter, that the object has. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif value Retrieves the value that is pointed to by the iterator.
Gg921812.pubmethod(en-us,AX.60).gif wait Pauses a process. (Inherited from Object.)
Gg921812.pubmethod(en-us,AX.60).gif xml Returns an XML string that represents the current object. (Inherited from Object.)

Top

Remarks

List iterators can be viewed as pointers into the lists over which they iterate. Functionality is available to start the iteration, determine whether more elements are available, and fetch the element that is pointed to by the iterator.

The order in which the elements occur during iteration is defined by the sequence in which the elements are inserted. Elements can be inserted by using the List.addStart, List.addEnd, or ListIterator.insert method.

It is better to use the ListEnumerator class than the ListIterator class. List iterators and the maps over which they iterate must be on the same client/server side. If you use the ListIterator class, and code is marked as Called from, it is possible that the list and the iterator will be on different tiers. In this case, the code will fail.

If you use the ListEnumerator class, the enumerator is automatically created on the same tier as the list. Additionally, to move to the next item in a list, you must explicitly call the more and next methods if you are using a list iterator. If you use the ListEnumerator class, you only have to call the moveNext method.

The only situation where you cannot use a list enumerator is where you need to delete elements from a list. For more information, see the delete method.

Examples

The following example creates a list and an iterator to point to it. It then uses various methods on the ListIterator class to print a description of the list, and the items in the list.

{ 
    List il = new List(types::Integer); 
    ListIterator it; 
  
    // Add some elements into the list. 
    il.addStart(1); 
    il.addStart(2); 
    il.addStart(4);  
  
    // Create a list iterator to traverse the values. 
    it = new ListIterator (il);  
  
    // Prints "int list iterator". 
    print it.definitionString();  
    // Prints "(begin)[4]". 
    print it.toString();  
  
    // Go on for as long as elements are found in the list. 
    // Prints 4, 2, 1. 
    while (it.more()) 
    { 
        print it.value(); 
        it.next(); 
    } 
    // Prints (end). 
    print it.toString(); 
    pause; 
}

Inheritance Hierarchy

Object Class
  ListIterator Class

See Also

List Class

ListEnumerator Class