Search code examples
javaternary-operator

Java "? :" operator?


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.


Solution

  • 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.