You're looking at a ternary operator:
Properly formatted, one looks like this:
foo.isSomething() ? doThis() : doThat();
and translates to: "If the expression before the ?
evaluates to true, execute the statement between the ?
and the :
, otherwise execute the statement after the :
."
In other words, you can think of this as shorthand for:
if (foo.isSomething()) {
doThis();
} else {
doThat();
}
Note that this is merely a shorthand - there's nothing you can do with a ternary operator that you can't do with if / else statements. That said, you should get familiar with them if you plan to learn programming by exploring professional code (which, incidentally, I recommend strongly), as you'll see it used a lot - not just in Java but in a multitude of languages.