0 votes
1 view
in Java by (5.5k points)

Is there a better way to negate a boolean in Java than a simple if-else?

if (theBoolean) {

    theBoolean = false;

} else {

    theBoolean = true;

}

1 Answer

0 votes
by (33.8k points)

Try:

theBoolean = !theBoolean;

...