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.8k answers
501 comments
693 users