iterator - Maple Help

Online Help

All Products    Maple    MapleSim


List.iterator

return iterator over List

List.listIterator

return listIterator over List

 

Calling Sequence

Description

Examples

Calling Sequence

java.util.Iterator<Algebraic> iterator( )

java.util.ListIterator<Algebraic> listIterator( )

java.util.ListIterator<Algebraic> 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<Algebraic> it = s.iterator();

        while (it.hasNext()) {

            System.out.println( "Element: " + it.next() );

        }

     ListIterator<Algebraic> 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

See Also

ExternalCalling/Java/MapleException

OpenMaple

OpenMaple/Java/Algebraic

OpenMaple/Java/API

OpenMaple/Java/List

OpenMaple/Java/List/contains

OpenMaple/Java/List/containsAll

OpenMaple/Java/List/select

OpenMaple/Java/List/toArray