Assignment Operators

Java provides a full suite of assignment operators, including the basic = assignment operator and the C op= style operators, where op is a binary arithmetic operator. These operators are as follows:

  • x = y— The variable x is assigned the value of y.

  • x += y— The variable x is assigned the value of x + y.

  • x -= y— The variable x is assigned the value of x – y.

  • x *= y— The variable x is assigned the value of x * y.

  • x /= y— The variable x is assigned the value of x / y.

  • x %= y— The variable x is assigned the value of x % y.

  • x &= y— The variable x is assigned the value of x & y.

  • x |= y— The variable x is assigned the value of x | y.

  • x ^= y— The variable x is assigned the value of x ^ y.

  • x <<= y— The variable x is assigned the value ...

Get Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.