In this Java for Testers tutorial, we will learn what is Ternary Operator in Java. The ternary operator in Java functions as a simplified if-else Java statement.
The ternary operator “?:” accepts three operands (boolean expression ? expression1: expression2)
The first expression must be a boolean expression, second and third are the expressions which can return any value. The Java Ternary operator returns expression1 if the first boolean expression is evaluated to true and expression2 if the first boolean operand evaluates to false.