No offense, Dhruv, but I think that is the ugliest
Java statement I have ever seen.
To evaluate it, you have to realize that the ternary operator is one of the few operators in Java that has
right-to-left associativity. In other words, when confronted with nested ternary operators, Java starts evaluating the rightmost one and works its way left from there.
Given that piece of information, I will simplify your original statement, step-by-step. Keep in mind, Dhruv, each of these statements is equivalent:
<PRE>
Step 1: false ? true ? 1 : true ? 2 : 3 : true ? 4 : true ? 5 : 6
Step 2: false ? true ? 1 : true ? 2 : 3 : true ? 4 : 5
Step 3: false ? true ? 1 : true ? 2 : 3 : 4
Step 4: false ? true ? 1 : 2 : 4
Step 5: false ? 1 : 4
Step 6: 4
</PRE>
HTH
Art