http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html
A ? B : C
tests A and evaluates to B if A is true, otherwise to C.
A must be a boolean expression (for example, x == 1) and B and C must be type-compatible.
In your case the end result is if (j == dataCont - 1) {
pfx = "";
}
else {
pfx = ", ";
}
place I used to work, they had a poll about whether people preferred using and seeing this style of code (the ternary operator) or explicitly setting out conditions. the plan was to make the most popular choice a part of the coding standards. never took off, but it was shocking how few people could understand such code. yikes
> Hi.
>
> I have the following line of code:
>
> > String pfx = (j == (dataCont - 1)) ? "" : ", ";
>
>
> Somebody can please explain me what means ? "" : ",
> ";
> in that line of code?
>
> Regards
if j equal dataConr-1 then the pfx=" " otherwise pfx=","