🚀 Welcome to MDriven Learn –  Don’t miss the latest Release Notes.
OCLOperators indexOf

indexOf ( object : T ) : Integer

Returns the position of object in sequence self.

Expression Result
Sequence{'a', 'b'}->indexOf('a') 0

The zero-based index of an object in the collection may be -1 if it does not exist.

(Note that the specification probably says that this should be 1-based and not 0-based, as it is. This makes it confusing to use the at(int)-operator, which IS 1-based.

We have introduced an IndexOf0:int that is explicitly zero-based to better align with the explicitly zero-based at0(int).)

We recommend you use IndexOf0 and at0 operators over IndexOf and at.