Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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 (46k points)

Try:

theBoolean = !theBoolean;

Related questions

0 votes
1 answer
asked Aug 6, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Oct 28, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...