🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators includesAll
This page was created by Alexandra on 2017-08-13. Last edited by Wikiadmin on 2026-08-17.

includesAll lets you test whether one collection contains every element in another collection. Use it in OCL when you need to verify that a required set of values is present in a collection.

Syntax

collection->includesAll(c2)
Part Meaning
collection The collection you want to search.
c2 The parameter collection whose elements must all be present in collection.
Result A Boolean value: true when every element of c2 is contained in collection; otherwise false.

Examples

The following expression returns true because both 3 and 4 are present in the sequence:

Sequence{1, 2, 3, 4, 5}->includesAll(Sequence{3, 4})

The following expression returns false because 7 is not present in the sequence:

Sequence{1, 2, 3, 4, 5}->includesAll(Sequence{3, 7})

Here are additional examples demonstrating includesAll with different collection types:

Expression Result
Sequence{2.3, 5.2, 'a', 3, null}->includesAll(Set{3, null}) true
Sequence{2.3, 5.2, 'a', 3}->includesAll(Set{3, null}) false
Sequence{2,4,3}->includesAll(Set{3,4})

The above will return true because 3,4 are in the sequence .

Sequence{2,4,3}->includesAll(Set{3,4,7})

This will return false because 7 is not in the sequence.

Note.

The sequence has to be of the same type like integers, float or string to avoid errors

Use compatible element types

Use collections with compatible element types. For example, compare integer values with integers, floating-point values with floating-point values, and strings with strings. Mixing incompatible types can cause errors.

includesAll and forAll

Use includesAll to check whether required elements occur in a collection. Use forAll when you need to evaluate a condition for every element instead.

For example, this checks for specific values:

Sequence{1, 2, 3, 4, 5}->includesAll(Sequence{3, 4})

A forAll expression checks a condition for each element, rather than checking for the presence of another collection.

See also