Possible duplicate:
Java - order of operations - using two assignment operators on a separate line
If we assign a variable a value in the chain as shown below,
int x=10, y=15; int z=x=y; System.out.println(x+" : "+y+" : "+z);
then the value of all three variables x , y and z will become 15 .
However, I do not understand the following phenomenon with an array.
int array[]={10, 20, 30, 40, 50}; int i = 4; array[i] = i = 0; System.out.println(array[0]+" : "+array[1]+" : "+array[2]+" : "+array[3]+" : "+array[4]);
It displays 10 : 20 : 30 : 40 : 0 . It replaces the value of the last element of array[4] with 0 .
As for the previous assignment operator - int z=x=y; , I expect that the value of the first element means array[0] to replace with 0 . Why is this not so? It is simple, but I cannot understand. Could you explain?
By the way, this assignment operator array[i] = i = 0; is fictitious and it has no intrinsic value in this code and should no longer be used, but I just wanted to know how it actually works in this case.
source share