The operator is your friend:
public static String translate(boolean trueOrFalse) {
return trueOrFalse ? "yes" : "no";
}
In general, if you find yourself writing:
SomeType x;
if (someCondition) {
x = someExpression;
} else {
x = someOtherExpression;
}
it is usually better to use:
SomeType x = someCondition ? someExpression : someOtherExpression;
The conditional statement ensures that only one of someExpressionor is evaluated someOtherExpression, so you can use method calls, etc., assured that they will not be executed improperly.
, , - .