Home >Java >javaTutorial >What does ? mean in java?
In Java, the question mark (?) represents the null conditional operator, also known as the ternary conditional operator, which provides a simplified if-else syntax: evaluating the Boolean expression condition. If condition is true, return value1; otherwise, return value2.
? Function in Java
In the Java programming language, the question mark (?) means Null value conditional operator , also known as ternary conditional operator. It is a simplified if-else syntax for evaluating a condition and returning a result in a single statement.
Syntax
##result = (condition) ? value1 : value2;
Use the method
Example
<code class="java">int age = 22; String result = (age > 18) ? "成年人" : "未成年人"; // result 的值为 "成年人"</code>
Advantages
Using the ? operator has the following advantages:The above is the detailed content of What does ? mean in java?. For more information, please follow other related articles on the PHP Chinese website!