Operators in Apex

Operators are the sign that operates on one or more operands.

Types of Operators:

OperatorsDescriptionSyntax
== operator (Assignment Operator) assigns the value of “y” to the value of “x”.  x = y
+=+= operator (Addition assignment operator) adds the value of “y” to the value of “x” and then it reassigns the new value to “x”.x += y
*=*= operator (Multiplication assignment operator)multiplies the value of “y” with the value of “x” and then it reassigns the new value to “x”.x *= y
-=-= operator (Subtraction assignment operator) substract the value of “y” with the value of “x”, and then it reassigns the new value of “x”.  x -= y
/=/= operator (Division assignment operator) divides the value of “x” with the value of “y” and then reassigns the new value of “x”.x /= y
|=|= operator(OR Assignment operator), If “x” (Boolean), and “y” (Boolean) both are false, then “x” remains false.  x |= y
&=&= operator, if “x” (Boolean), and “y” (Boolean) both are true, then “x” remains true.x &= y
&&&& operator (AND logical operator) it shows “short-circuiting” behavior that means “y” is evaluated only if “x” is true.x && y
|||| OR logical operator.x || y
==== Operator, if the value of “x” equals to the value of “y”, then the expression evaluates true.  x == y
====== operator, if “x” and “y” reference the same location in the memory, then the expression evaluates true.x === y
++++ Increment operator.X ++
     —— Decrement operator.x —

Example: 

Output:

Salesforce Operators in Apex

Example: Addition assignment operator.

Output:

Salesforce Operators in Apex

Example: Multiplication Assignment Operator

Output:

Salesforce Operators in Apex

Example: Division Assignment Operator

Output:

Salesforce Operators in Apex

Example: Subtraction Assignment Operator

Output:

Salesforce Operators in Apex

Pin It on Pinterest

Share This