OCLOperators indexOf
(Adding message template to the top of the page)
(Updated Edited template to July 12, 2025.)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{message|Write the content here to display this box}}
<message>Write the content here to display this box</message>
=== indexOf ( object : T ) : Integer ===
=== indexOf ( object : T ) : Integer ===
Returns the position of ''object'' in sequence ''self''.
Returns the position of ''object'' in sequence ''self''.
Line 10: Line 10:
|}
|}
The zero-based index of an object in the collection is possibly -1 if nonexistent.
The zero-based index of an object in the collection is possibly -1 if nonexistent.
(note that probably the specification says that this should be 1-based and not 0-based as it is. This makes it a confusing to use the at(int)-operator that IS 1 based.
We have introduced a IndexOf0:int that explicitly is zero based to better sit with the explicit zero based at0(int))
We recommend you use [[Documentation:OCLOperators indexOf0|IndexOf0]] and [[Documentation:OCLOperators at0|at0]] operators over IndexOf and at
[[Category:OCL Collection Operators]]
[[Category:OCL Collection Operators]]
{{Edited|July|12|2024}}
{{Edited|July|12|2025}}

Latest revision as of 05:57, 20 January 2025

This page was created by Alexandra on 2017-08-13. Last edited by Edgar on 2025-01-20.

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 is possibly -1 if nonexistent.

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

We have introduced a IndexOf0:int that explicitly is zero based to better sit with the explicit zero based at0(int))

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

MDriven Chat

How would you like to chat today?

Setting up your conversation…

This may take a few moments