The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search

Trail: Learning the Java Language
Lesson: The Nuts and Bolts of the Java Language

## Ternary Operator

> The Java programming language supports one ternary operator--the `?:` operator. This operator is a conditional operator and is short-hand for an `if`-`else` statement:

> >     op1 ? op2 : op3

> The `?:` operator returns `op2` if `op1` is true or returns `op3` if `op1` is false.

| Start of Tutorial > Start of Trail > Start of Lesson | Search