🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators not equal to
This page was created by Charles on 2025-11-18. Last edited by Wikiadmin on 2026-07-29.

You can use the not equal to operator in OCL expressions to test whether two values or objects differ; this page is for modelers writing conditions, constraints, and validation rules.

Symbol

<>

The <> operator is a comparison operator. It returns a Boolean value:

  • true when the left-hand operand is different from the right-hand operand.
  • false when the operands are equal.

In the mathematical-symbol definition, <> has the form <> ( object : OclAny ) : Boolean and returns true when self is a different object from object. See Documentation:Mathematical symbols for the operator definitions.

Compare an attribute with a value

Assume that the Department class has a DepartmentName attribute. Use <> in the context of one Department to test that its name is not 'Projects':

context Department
self.DepartmentName <> 'Projects'

The expression produces the following result for each Department evaluated:

DepartmentName Expression result
'Sales' true
'Projects' false

This expression evaluates one Department at a time. It does not by itself test every Department in a collection. When you need a collection-wide rule, use the appropriate collection expression in addition to the comparison.

Use in a condition

You can use the Boolean result wherever an OCL condition is required. For example, the following condition is true for a Department whose name is anything other than 'Projects':

self.DepartmentName <> 'Projects'

Use parentheses when combining this comparison with other Boolean expressions so that the intended condition is clear. For Boolean alternatives, see the Or operator and the Xor operator.

Not equal versus not null

<> compares two operands. It is not the operator for testing whether a value is null. To test whether a value has a value rather than being null, use notNull.

See also