🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators removeAt
This page was created by Hans.karlsen on 2021-12-21. Last edited by Wikiadmin on 2026-07-29.

You can use removeAt in OCL Executable Action Language (EAL) expressions when you need to remove an association or collection element by its numeric position rather than by the identity of the object.

Syntax

Collection.removeAt(index: Integer)
Part Meaning
Collection The association or collection from which you want to remove an element.
index An integer that identifies the element position. Indexing is zero-based: the first element is 0, the second is 1, and so on.

Remove an element by position

Use removeAt when the position is known and is the reason for selecting the element.

  1. Identify the association or collection to change.
  2. Determine the zero-based position of the element to remove.
  3. Call removeAt with that position.

For example, to remove the first order in the current object's Orders collection:

self.Orders.removeAt(0)

This expression targets self.Orders and removes the element currently at index 0. It removes that specific association or collection entry from the current context.

Index behavior after removal

After an element is removed, later elements move down one position. For example, if Orders contains three entries at indexes 0, 1, and 2, removing index 0 causes the entry that was at index 1 to become the new index 0.

This matters when you perform more than one index-based removal: each removal changes the positions used by later removeAt calls.

Example

Given an Orders collection where the first listed order is the one to remove:

self.Orders.removeAt(0)

The first order is removed from self.Orders. The order previously in the second position becomes the first element in the collection.

See also