? : is the Conditional operator and is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide, which value should be assigned to the variable.
Syntax:
variable y = (expression) ? value if true : value if false
Example:
public class Test
{
public static void main(String args[])
{
int x, y;
x = 10;
y = (x == 1) ? 20: 30;
System.out.println( "Value of y is : " + y );
y = (x == 10) ? 20: 30;
System.out.println( "Value of y is : " + y );
}
}