Conditional Expressions
-
Shorthand conditional - Puts everything in one line.
-
Also known as a ternary operator.
-
Use sparingly, can be confusing to you and others!
variable = (condition) ? (true action) : (false action);
... is the same as ...
if (condition) {
variable = true value;
} else {
variable = false action;
}
-
Use either in class, but I highly recommend the long version.
Back to Java slides
Home
Internet II: Day 2