? :

The operator ? : is the only ternary operator in Java. It is used as a conditional expression using the form:

expression1 ? expression2 : expression3

where expression1 evaluates to a boolean. If expression1 evaluates to true the entire conditional expression will evaluate to expression2. If expression1 evaluates to false the entire expression will evaluate to expression3.

For example:

String a = x > y ? "x is > y" : "x isn't > than y";
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License