0 votes
1 view
in Java by (10.2k 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 (46.1k points)

Try:

theBoolean = !theBoolean;

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 28 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...