Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java "? :" operator? [duplicate]

Possible Duplicate:
What is the Java ?: operator called and what does it do?

hi, may i know what is the java ?: operator called, i am trying to find information on how it works but i do not know what is it called, typing ?: in google dont give a correct result.

like image 985
sutoL Avatar asked Jun 21 '10 14:06

sutoL


1 Answers

It's the conditional operator.

Some people call it the ternary operator, but that's really just saying how many operands it has. In particular, a future version of Java could (entirely reasonably) introduce another ternary operator - whereas the name of the operator is the conditional operator.

See section 15.25 of the language specification:

The conditional operator ? : uses the boolean value of one expression to decide which of two other expressions should be evaluated.

like image 51
Jon Skeet Avatar answered Oct 03 '22 02:10

Jon Skeet