Java : Assignment Operators

Assignment Operator also called as op= operators and it’s used to reduce the expression size.

Following is the list of complete op= operators



+=
-=
*=
/=
%=
<>=
>>>=
&=
|=
^= 

See Also :

For Example : count +=2 has the will return the same result as expression statement : count = count + 2 ;

public class TestClass {

  public static void main(String[] arg) {
    int count1 = 5 , count2 = 5;

	//Calculation with assignment operator
    count1 += 2;
    System.out.println(count1);
    //equivalent matematical operation
    count2 = count2 + 2;
    System.out.println(count2);
  }
}

Output


7
7