Print
Operators

The following chart is a complete list and description of all operators present in MVEL.

Unary Operators

Operator Description Example
new Object instantiation new String("foo")
with Block WITH Operator. Perform multiple operations on a single object instance with (value) { name = 'Foo', age = 18, sex = Sex.FEMALE }
assert Assert that a value is true or fail with an AssertionError assert foo != null

Comparison Operators

Operator Description Example
== Equality Check.  Checks to see if the values on both sides of the operator are equal.  Unlike Java, this is not an identity check. 

"foo" == "foo" is true

!= Not Equals Check.  Checks to see if the values on both sides of the operator are not equal.

"foo" == "bar" is false

> Greater Than Check.  Checks to see if the value on the left side of the operator is greater than than value on the right.

2 > 1 is true

< Less Than Check.  Checks to see if the value on the left side of the operator is less than value on the right.

1 < 2 is true

>=

Greater Than or Equal.  Checks to see if the value on the left hand side is greater than or equal to the value on the right.

1 >= 1 is true

<= Less Than or Equal.  Checks to see if the value on the left hand side is less than or equal to the value on the right.

2 <= 2 is true

contains Value Containment Check.  Checks to see if the value on the left contains the value on the right.  For more details on how this operator works, see [Contains Operator]

var contains "Foo"

is or instanceof

Type Checking Operator.  Checks to see if the value on the left is a member of the class on the right. 

var instanceof Integer

strsim String Similarity Check.  Compares to strings and returns a similarity between them as a percentage. See: String Similarity Check.

"foobie" strsim "foobar"

soundslike Soundex Check.  Performs a soundex comparison between two strings. See: [Soundex].

"foobar" soundslike "fubar"

Logical Operators

Operator Description

Example

&& Logical AND.  Checks to see that the values on both sides of the operator are true.

foo && bar

|| Logical OR.  Checks to see if either the value on the left or the right is true.

foo || bar

or

Chained OR.  Checks a sequence of values for emptiness and returns the first non-empty value.

foo or bar or barfoo or 'N/A'

~= Regular Expression Match.  Checks to see if the value on the left matches the regular expression on the right.

foo ~= '[a-z].+'

Bitwise Operators

Operator Description

Example

& Bitwise AND.

foo & 5
| Bitwise OR.

foo | 5
^ Bitwise XOR.

foo ^ 5

Arithmetic Operators

Operator Description

Example

+

Addition.  Adds the value on the left to the value on the right

1 + 2

- Subtraction.  Subtracts the value on the right from the value on the left

2 - 1

/ Division.  Divides the number on the left by the number on the right

2 / 1

*

Multiplication.  Multiples the number on the left by the number on the right

1 * 2

%

Modulus.  Divides the number on the left by the number on the right and returns the remainder.

2 % 1

Other Operators

Operator Description

Example

+ String Concatenation.  Overloaded operator for concatenating two strings together.

"foo" + ;bar"

# Concatenation Operator.  Concatenates two literals as strings.

1 # 2 returns "12"

in Projection/Fold. Projects across a collection.  See: Projections and Folds.

(foo in list)

=

Assignment.  Assigns the value on the right to the variable on the left.

var = "foobar"

Powered by Atlassian Confluence