Unknown Operator

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
[259 byte] By [karma1234a] at [2007-10-3 10:15:57]
# 1
Do you have more code?
ChargersRulea at 2007-7-15 5:36:41 > top of Java-index,Java Essentials,New To Java...
# 2
It could be a space, or a comma between 2 word. All depends on the code.
ChargersRulea at 2007-7-15 5:36:41 > top of Java-index,Java Essentials,New To Java...
# 3

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 = ", ";

}

jverda at 2007-7-15 5:36:41 > top of Java-index,Java Essentials,New To Java...
# 4
ThanksKind regards
karma1234a at 2007-7-15 5:36:42 > top of Java-index,Java Essentials,New To Java...
# 5

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

georgemca at 2007-7-15 5:36:42 > top of Java-index,Java Essentials,New To Java...
# 6

> 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=","

eaajea at 2007-7-15 5:36:42 > top of Java-index,Java Essentials,New To Java...
# 7
> if j equal dataConr-1 then the pfx=" " otherwise> pfx=","Next time you might want to try reading the thread before you respond. The question has already been answered.
jverda at 2007-7-15 5:36:42 > top of Java-index,Java Essentials,New To Java...