Neha Daga wrote:comment line 1 and compile the program.
yes, if we commented out line 1
offcourse the output would be : 2 1 0 
that is my question why in above code output is not 2 1 0 ?
Joined: Oct 30, 2009
ok I will explain you line by line:
After line1, set has 2 values 45 & 46 represented by i1 and i2.
Now, after line2, i2 now refers to 47 ans since wrapper objects are immutable it will be a new object and will not change the value of the object added to set.
Now, at line 3 you are trying to remove object refered by i2 i.e 47, which is not there in set so nothing will be removed from set and it will give the output:
2 1 1 
add this line instead of line 12:
you will see that its returning false indicating that it is unable to find i2 with a value of 47. So confirming that 46 still remains in the collection and the rest of the explanation is same as its been told above.