Booleans can also be "negated" using the "not" operator - !.
boolean haveOreosInHouse = true;
boolean stuckToCalorieLimit = !haveOreosInHouse;So in this case, I have stuck to my calorie limit if there are not Oreos in the house.
| haveOreosInHouse | stuckToCalorieLimit |
|---|---|
| false | true |
| true | false |
boolean isLoggedIn = false;
boolean isGuest = !isLoggedIn;Now in this case, if user is not logged in he is a guest.
| isLoggedIn | isGuest |
|---|---|
| false | true |
| true | false |