What is the /= operator in Java?
It is an abbreviation for x = x / y (x /= y)
. What it does is it divides the variable to be asigned by the left hand side of it and stores it in the right hand side. You can always change:
x = x / y
to
x /= y
You can do this with most other operators like * / +
and -
. I am not sure about bitwise operators though.
a/=b; implies that divide a with b and put the result into a
It's a combination division-plus-assignment operator.
a /= b;
means divide a
by b
and put the result in a
.
There are similar operators for addition, subtraction, and multiplication: +=
, -=
and *=
.
%=
will do modulus.
>>=
and <<=
will do bit shifting.