Ternary operator lets you assign a value to a variable based on a boolean expression if true then one value if false then another value. In simple language, a ternary operator is a conditional operator, which can be used as an alternative to the Java if/then/else syntax, but it goes beyond that, and can even be used on the right-hand side of Java statements.It is mainly used when the variables are initialized based on the conditions.
minVal = (a < b) ? a : b;
absValue = (a < 0) ? -a : a;