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

# Online Help

###### All Products    Maple    MapleSim

List.searchFirst

return first index of element within a list

List.searchLast

return last index of element within a list

 Calling Sequence int searchFirst( Algebraic expr ) throws MapleException int searchLast( Algebraic expr ) throws MapleException

Description

 • The searchFirst function returns the leftmost index of expr in the List, or 0 if expr is not an element of the List.
 • The searchLast 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 one-based; that is, the index of the first element is 1 and the index of the last element equals the result of numElements. See indexOf and lastIndexOf for functions which are equivalent but zero-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: " + searchFirst( three ) ); System.out.println("Rightmost index of 3: " + searchLast( three ) ); System.out.println("Leftmost index of 4: " + searchFirst( four ) ); System.out.println("Rightmost index of 4: " + searchLast( four ) ); } }

Executing this code produces the following output.

 Leftmost index of 3: 2 Rightmost index of 3: 4 Leftmost index of 4: 0 Rightmost index of 4: 0