Home Segments Top Top Previous Next

396: Mainline

The following is the pattern for Java's value-producing conditional-operator expression:

Boolean expression ? if-true expression : if-false expression 

In contrast to the operators that you have seen so far, the conditional operator consists of a combination of distributed characters, ? and :, separating three operands—the Boolean expression, the if-true expression, and the if-false expression. Thus, the conditional operator combination is said to be a ternary operator.