Back
Is there a better way to negate a boolean in Java than a simple if-else?
if (theBoolean) { theBoolean = false;} else { theBoolean = true;}
if (theBoolean) {
theBoolean = false;
} else {
theBoolean = true;
}
Try:
theBoolean = !theBoolean;
31k questions
32.9k answers
500 comments
693 users