Unexpected Results when Using Cursors

Effect

You get unexpected results when using cursors. For example, the elementAt function fails for the given cursor or returns an unexpected element.

Reason

You have used an undefined cursor. Cursors become undefined when an element is added to or removed from the collection.

Solution

Cursors that become undefined must be rebuilt with an appropriate operation (for example, locate) before they are used again. Rebuilding is especially important for removing all elements with a given property from a collection. Elements cannot be removed by coding a cursor iteration. Use the removeAll function that takes a predicate function as its argument.



Introduction to the Collection Classes
Removing Elements
Overview of Iteration
Iteration with Cursors
Iteration with allElementsDo


Removing an Element from a Collection
Using Cursors to Locate and Access Elements
Using Cursors to Iterate Over a Collection
Using allElementsDo and Applicators to Iterate Over a Collection
Cursors vs. Exception Handling
Instantiating the Collection Classes