int a = b ? c : a

could someone please point me to a page that explains what the code fragment in the subject title means? I have seen this in some uncommeted code but have no idea what it means (though do have an inlinking).techyoung
[230 byte] By [techyounga] at [2007-11-27 4:48:19]
# 1
if( b ) a = c;This is most close to your code.:)But your code will not be compiled as I can see.
Michael.Nazarov@sun.coma at 2007-7-12 10:01:11 > top of Java-index,Java Essentials,Java Programming...
# 2

It's wrong because a is undefined. So it's probably a compiler error.

int a = b ? c : d;

would be more appropriate, assuming c and d are ints and b is a boolean. It's called a ternary operator. It's shorthand for this:

int a;

if(b)

a = c;

else

a = d;

bsampieria at 2007-7-12 10:01:11 > top of Java-index,Java Essentials,Java Programming...
# 3
? :That's the ternary operator.It's kind of a check statement."b ? c : a"> means, If "b" is true, then return "c", otherwise return "a"
aasantaviccaa at 2007-7-12 10:01:11 > top of Java-index,Java Essentials,Java Programming...
# 4
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html
Hippolytea at 2007-7-12 10:01:11 > top of Java-index,Java Essentials,Java Programming...