Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java plus equals or equals plus operator? [duplicate]

Tags:

java

Is += the same as =+?

I can't find any reason for why the plus sign is reversible. For what reasons would I need to use one of the other? Where can i find docs on this i tried searching but didnt see the use of both.

like image 478
117 Avatar asked Jul 12 '15 08:07

117


People also ask

Is it += or =+ in Java?

=+ does nothing; it's the same as = here. You have just written sum1 = two . sum2 += one on the other hand is essentially the same as sum2 = sum2 + one .

Can you do += in Java?

It's the Addition assignment operator. Let's understand the += operator in Java and learn to use it for our day to day programming. x += y in Java is the same as x = x + y. It is a compound assignment operator.

What does plus equals do in Java?

The plus-equals operator ( += ) adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left.

What is the == operator in Java?

== operator is a type of Relational Operator in Java used to check for relations of equality. It returns a boolean result after the comparison and is extensively used in looping statements and conditional if-else statements.


1 Answers

It's not the same.

x+=5 is equivalent to x=x+5.

x=+5 (or x=(+5)) is equivalent to x=5.

like image 162
Eran Avatar answered Oct 04 '22 08:10

Eran