Shorthand Operator in Java

Some unique Compound Assignment Operators commonly referred to as Shorthand Assignment Operators are provided by Java. Because it offers a quick way to appoint an expression to a variable, it is known as shorthand.

The above operator can be used to link the assignment operator and the algebraic operator.

You might, for instance, write:

a = a-7;

The aforementioned sentence can also be expressed in Java as follows:

a -= 7;

Java uses a variety of compound assignment operators, including:

OperatorDescription
+=First performs addition and then assigns
-=First performs subtraction and then assigns
*=First performs multiplication and then assigns
%=First performs modulo and then assigns
/=First performs division and then assigns
<<=Left Shift in Binary and assigns
>>=Right Shift in Binary and assigns
>>>=Shift right and assigns zeros
&=Binary AND assigns
^=Binary assignment and exclusive OR
|=Binary assignment and inclusive OR

Example:

ShorthandoperatorExpl.java

Output:

Shorthand Operator in Java