indexOf - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

# Online Help

###### All Products    Maple    MapleSim

List.indexOf

return first index of element within a list

List.lastIndexOf

return last index of element within a list

 Calling Sequence int indexOf( Algebraic expr ) int lastIndexOf( Algebraic expr )

Description

 • 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.

Examples

 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