iterator - Maple Help

List.iterator

return iterator over List

List.listIterator

return listIterator over List

 Calling Sequence java.util.Iterator iterator( ) java.util.ListIterator listIterator( ) java.util.ListIterator listIterator( int index )

Description

 • The iterator function returns an Iterator object which can be used to iterate over the List.
 • The listIterator function returns an ListIterator object which can be used to iterate over the List.  The optional argument index specifies a zero-based starting index.
 • Both iterators traverse the list in list order, but the ListIterator can also be used to traverse the list in reverse order.

Examples

 import java.util.Iterator; import java.util.ListIterator; import com.maplesoft.openmaple.*; import com.maplesoft.externalcall.MapleException; class Example { public static void main( String notused[] ) throws MapleException { String[] mapleArgs = { "java" }; Engine engine = new Engine( mapleArgs, new EngineCallBacksDefault(), null, null ); List s = (List)engine.evaluate( "[2,7.5,-1];" ); Iterator it = s.iterator(); while (it.hasNext()) { System.out.println( "Element: " + it.next() ); } ListIterator lit = s.listIterator(); while (lit.hasNext()) { System.out.println( "Forward: " + lit.next() ); } while (lit.hasPrevious()) { System.out.println( "Reverse: " + lit.previous() ); } } }

Executing this code produces the following output:

 Element: 2 Element: 7 Element: 5 Element: -1 Forward: 2 Forward: 7 Forward: 5 Forward: -1 Reverse: -1 Reverse: 5 Reverse: 7 Reverse: 2