Reputation: 51
Test code:
int[] test = {0, 1, 2, 3};
System.out.println("test1[3] ++== 0 is " + (test[3] ++== 0));
Result:
test1[3] ++== 0 is false
So it must be some sort of logical operator but I have not been able to find any documentation. Searching the Internet yielded no reference.
Please help? Thanks in advance.
Upvotes: 4
Views: 193
Reputation: 2568
Since ++ is a post-increment, your actions can be separated as:
false
test[3] = test[3] + 1;
So after that in the test[3]
will be value 4
Upvotes: 1
Reputation: 5188
It's two operators - increment by one (x++
) and test for equality (x==0)
. You should read it as (x++) == 0
.
The tricky thing is that the increment happens after the comparison, so the above means "test if X is zero, then increment X by one."
Upvotes: 1
Reputation: 158
x++==y
is equivalent to x++ == y
public class Test {
public static void main(String args[]) {
int[] test = {0, 1, 2, 3};
System.out.println("test1[3] ++== 0 is " + (test[3] ++== 3));
}
}
test1[3] ++== 0
will equate to false
.
test1[3] ++== 3
will equate to true
.
Upvotes: 1
Reputation: 8626
The way the text is presented looks like it would be a special case ++==
, but in fact you should read it as follows:
test[3]++ == 0
Basically, the result of test[3]++
will be compared (i.e ==
) with 0
.
And this basically reads as (test[3]=3) == 0
, which is false.
The ++
is a postfix operator which is shortcut for value = value + 1
.
The ==
is a comparison between two values.
The text is just badly formatted, that's all.
Upvotes: 7
Reputation: 451
++
and ==
are two independent operators. ++
is post-incrementing the value of test[3]
, then that is being compared to 0.
Upvotes: 3