List.indexOf
return first index of element within a list
List.lastIndexOf
return last index of element within a list
Calling Sequence
Description
Examples
int indexOf( Algebraic expr )
int lastIndexOf( Algebraic expr )
The indexOf function returns the leftmost index of expr in the List, or 0 if expr is not an element of the List.
The lastIndexOf function returns the rightmost index of expr in the List, or 0 if expr is not an element of the List,
The indices returned are zero-based; that is, the index of the first element is 0. See searchFirst and searchLast for functions which are equivalent but one-based.
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 l = (List)engine.evaluate( "[1,3,7,3,10]:" );
Numeric three = engine.newNumeric( 3 );
Numeric four = engine.newNumeric( 4 );
System.out.println("Leftmost index of 3: " + indexOf( three ) );
System.out.println("Rightmost index of 3: " + lastIndexOf( three ) );
System.out.println("Leftmost index of 4: " + indexOf( four ) );
System.out.println("Rightmost index of 4: " + lastIndexOf( four ) );
}
Executing this code produces the following output.
Leftmost index of 3: 1
Rightmost index of 3: 3
Leftmost index of 4: -1
Rightmost index of 4: -1
See Also
ExternalCalling/Java/MapleException
OpenMaple
OpenMaple/Java/Algebraic
OpenMaple/Java/API
OpenMaple/Java/Indexable
OpenMaple/Java/List
OpenMaple/Java/List/assign
OpenMaple/Java/List/contains
OpenMaple/Java/List/containsAll
OpenMaple/Java/List/searchFirst
Download Help Document