OCLOperators add
Created by Lars.olofsson on 2018-10-28 · Last edited by Colline.ssali on 2025-12-29.
.add ( object : T )
The add() operator is used to insert an element into a collection, returning a new collection that includes the added element. Unlike append, which adds an element only to the end of an ordered collection, add can be used more generally to include an element in a collection without relying on order. The original collection remains unchanged.
Adds the object to a sequence, for example, an association.
| Expression | Result |
|---|---|
| self.<association of type T>.add(<object : T>) | The object has been added to the existing association |
Syntax:
collection->add(element)Example:
Add Department to a collection
Note! Add changes the sequence or association. If you want to append (add) an object to a sequence and return the result (without changing the underlying data), use ->append.
