Using the sequential iterator

You iterate over collection members using iterators.

The APIs have two types of iterators: dkIterator and DKSequentialIterator.

Java™

dkIterator, the base iterator, supports the next, more, and reset methods. The subclass DKSequentialIterator contains more methods. You create an iterator by calling the createIterator method on the collection. After creating the iterator, you can use its methods to traverse the collection. The following example shows how to use an iterator:

dkIterator iter = sq.createIterator(); //create an iterator for sq
Object member;
while(iter.more()) { //While there are more members
member = iter.next(); //move to the next member and get it
System.out.println(member);
.... 
}

This code allows you to perform some operations on the current member before moving to the next member. Such an operation could be replacing a member with a new one, or removing it.

Example: Java

String st1 = "the new first member";
sq.replaceElementAt(st1, iter); //replace current member with a new one
....                              // or
sq.removeElementAt(iter);      // remove the current member
....
When removing a member inside a loop, check it as in the following example. Create a new iterator when an item is deleted from the iterator.

Example: Java

   ....
   if (removeCondition == true)
     sq.removeElementAt(iter); //remove current member, do not advance the
                               //iterator since it is advanced to the next
                               //after the removal operation
   else
        iter.setToNext();   //if no removal, advance the iterator to the
   ....                    //next position