The Java ternary operator is a shorthand for an if-else statement. It has the syntax:
condition ? expression1 : expression2;
If the condition is true, expression1 is executed; if false, expression2 is executed.
Example:
int age = 18;
String result = (age >= 18) ? “Adult” : “Minor”;
System.out.println(result); // Output: Adult
Here, if age is greater than or equal to 18, the result will be “Adult”; otherwise, it will be “Minor”. The ternary operator is a compact alternative to simple conditional checks.