Kevin Griffin Kevin Griffin - 1 year ago 88
Java Question

Cleanest way to toggle a boolean variable in Java?

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

if (theBoolean) {
theBoolean = false;
} else {
theBoolean = true;

Answer Source
theBoolean = !theBoolean;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download