Possible Duplicate:
What is the Java ?: operator called and what does it do?
I am trying to read an implementation of a binary tree, and I ran across this one line of code:
if (...) {
...
} else {
node = ( node.left != null ) ? node.left : node.right; //this line
}
return node;
Can anyone tell me what this line means? My best guess is that it’s a conditional statement of some kind.
It is called
Conditional Operator.In
expression1 ? expression2: expression3, theexpression1returns abooleanvalue. If it istruethenexpression2is evaluated, elseexpression3is evaluated.So in your code snippet: –
is equivalent to: –