Is there a better way to negate a boolean in Java than a simple if-else?
if (theBoolean) theBoolean = false; else theBoolean = true;
Is there a better way to negate a boolean in Java than a simple if-else?
if (theBoolean) theBoolean = false; else theBoolean = true;
theBoolean ^= true;
Less keystrokes if your variable is longer then four letters :)
theBoolean = theBoolean ? false : true;
EDIT : Why do you have to? Just test the opposite as below :
if (!theBoolean) {
// do stuff;
}