Grokking Java Basics
Vote

0% completed

​

Java Ternary Operator

The ternary operator in Java is a shorthand for the if-else statement. It allows you to write a simple conditional assignment in a single line. This operator is especially useful for concise code when you need to choose between two values based on a condition.

Syntax

variable = (condition) ? expression1 : expression2;
  • condition: A boolean expression that is evaluated.
  • expression1: The value assigned to the variable if the condition is true.
  • expression2: The value assigned to the variable if the condition is false.

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content