I'm new to Java. Please explain the +=
and !=
operators. I can't find where they're documented. I'd like a site that explains them.
Asked
Active
Viewed 119 times
-4

Michael Petrotta
- 59,888
- 27
- 145
- 179

arkmabat
- 125
- 1
- 7
-
_Oddly I can't find it documented anywhere_ What did you try looking up? – Sotirios Delimanolis Jan 11 '14 at 04:17
-
your title says += and question shows =!? – SpringLearner Jan 11 '14 at 04:18
-
2Gee. "java operators" on Google somehow, after great difficulty, managed to bring up http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html as the VERY FIRST result... – Marc B Jan 11 '14 at 04:19
-
You probably mean `!=` instead of `=!`. The former is in the same style as `+=`, the latter is just an assignment of the inverse value. – Jeroen Vannevel Jan 11 '14 at 04:20
-
1Mark, I already went through that and it doesn't explain it. – arkmabat Jan 11 '14 at 04:21
-
Forgive me for my stupidity... I'm just trying to learn instead of cut and paste... I'll look at the related. – arkmabat Jan 11 '14 at 04:24
-
@Marc B, can you show where it is explained in the link you provided? – dansalmo Jan 11 '14 at 04:27
-
@dansalmo In the table, it's under assignment operator. In the links to the left, there's an article on assignment operators. – Sotirios Delimanolis Jan 11 '14 at 04:28
-
Yes, I saw that, still no explanation. Can you find one? – dansalmo Jan 11 '14 at 04:30
-
@dansalmo `You can also combine the arithmetic operators with the simple assignment operator to create compound assignments. For example, x+=1; and x=x+1; both increment the value of x by 1.` – Sotirios Delimanolis Jan 11 '14 at 04:31
-
2@dansalmo: search the page. It'll show up. Perhaps it's better to force the OP to **THINK** a bit for themselves and actually do a bit of **READING**. If all we do here is spoon feed pablum to the educationally ignorant, we'll just keep getting flooded with utterly trivial silly questions like this. – Marc B Jan 11 '14 at 04:31
-
@MichaelPetrotta hey it was not for you it was for Op Sorry – SpringLearner Jan 11 '14 at 04:35
-
Sorry. I can see dansalmo's point. I can delete the question if necessary. Sorry for the edits. I'm not a very good/accustomed member yet... – arkmabat Jan 11 '14 at 04:37
-
So the answer was not on the page you linked to, it was buried in another page. You should stick to helping people that already know the answers to the questions they are asking. The java docs suck. This OP's question and the answers below will help 1000's of others in the future. – dansalmo Jan 11 '14 at 04:38
2 Answers
2
For this +=
see the link provided in the comment of @cristian Java's +=, -=, *=, /= compound assignment operators
To explain =! I am giving example
boolean a=true;
boolean b=true;
System.out.println(a=!b);
It will print false
reason
b
is true
,!
of b
means false and you are assigning a
with false
The original post was =!
and not its has been changed to !=
!=
means not equal to
If you want to compare whether 2 are same or not then we use !=
Example
int i=1;int j=2;
if(i!=j)
{
System.out.println("not equals");
}
outputnot equals

Community
- 1
- 1

SpringLearner
- 13,738
- 20
- 78
- 116
-
-
-
1You should make it clearer that `=!` is a combination of two operators: the assignment operator and the unary negation operator. – Sotirios Delimanolis Jan 11 '14 at 04:30
-
@SotiriosDelimanolis ohho now I understand.I thought that my answer is wrong so you asking me something – SpringLearner Jan 11 '14 at 04:32
-
@SotiriosDelimanolis The original post was =! and now it has been changed to != – SpringLearner Jan 11 '14 at 04:34
-
1
-
-
-
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44994/discussion-between-jquerylearner-and-sotirios-delimanolis) – SpringLearner Jan 11 '14 at 04:55
2
The +=
operator works as so:
int x;
x += 3;
//Expands into: x = x + 3;
!= is just Logical NOT Equal To:
5 != 6 //True
5 != 5 //False

Tdorno
- 1,571
- 4
- 22
- 32