Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In Java, an inline if-statement is known as the ternary operator and it has the following syntax:

condition ? true statement : false statement;

Here, the condition is evaluated and if it is true, the true statement is executed, otherwise, the false statement is executed. For example:

int x = 10;

String result = (x > 5) ? "x is greater than 5" : "x is less than or equal to 5";

In this example, the condition is (x > 5) which evaluates to true, so the true statement "x is greater than 5" is assigned to the variable result.