# Operators in groovy

In groovy, operators are symbols which are used to tell the compiler to perform specified operations.

Following are the operators in groovy:

• Arithmetic operators
• Unary operators
• Assignment arithmetic operators
• Relational operators
• Logical operators
• Bitwise operators
• Conditional operators

## Arithmetic operator

Arithmetic operators are the basic mathematical operators, which are used to perform addition, subtraction, multiplication, division, Remainder and Power.

### Example 1:

Output:

In groovy, we also have some functions which are used to perform Arithmetic operations like plus, minus, intdiv and power. The use of these functions are shown in the example which is given below.

Output:

## Unary operators

In groovy, Unary operators require only one operator to perform the operation. Unary operators are used to perform the operations such as increment/decrement, negating, and inverting the values of a Boolean.

Output:

Output:

## Assignment arithmetic operators

In groovy, assignment arithmetic operators are used to assign a new value to the variable.

Output:

## Relational operators

In groovy, relational operators are used to compare two objects to check wether they are same or different or one is greater than, less than or equal to other object.

Output:

## Logical operators

In groovy, there are 3 logical operators for Boolean expression, and these operators are AND(&&), OR(||) and NOT(!)

Output:

Output:

Output:

## Bitwise operators

In groovy, Bitwise operators are used for operating on binary digits or bits of an integer.

Output:

Output:

## Conditional operators

In groovy, there are three types of conditional operators they are as follow:

• Not operator

In groovy, "not" operator is used invert the result of the Boolean expression.

### Example 12:

Output:

• Ternary operator

In groovy, Ternary Operator is the shortcut of if/else

### Example 13:

Output:

• Elvis operator

In groovy, Elvis operator is a shorthand property of the ternary operator. It only returns when a value is true.

Output: