The op= Operators : Operators « Operators « Java Tutorial






count += 5 has the same effect as the statement: count = count + 5;

public class MainClass {

  public static void main(String[] arg) {
    int count = 1;

    count += 5;
    System.out.println(count);

    count = count + 5;
    System.out.println(count);

  }

}
6
11

The complete set of op= operators:

  1. +=
  2. -=
  3. *=
  4. /=
  5. %=
  6. <<=
  7. >>=
  8. >>>=
  9. &=
  10. |=
  11. ^=








3.1.Operators
3.1.1.Six categories of operators
3.1.2.Operator Precedence
3.1.3.The op= Operators
3.1.4.The ternary operator (The Conditional Operator): result = value>conditionValue ? result1 : result2
3.1.5.Tests all the operators on all the primitive data types to show which ones are accepted by the Java compiler