We use cookies to give you a better experience, if that’s ok you can close this message and carry on browsing. For more info read our cookies policy.
We use cookies to give you a better experience. Carry on browsing if you're happy with this, or read our cookies policy for more information.
2.9

# Unary operator

The word ‘unary’ refers to a single unit. Unary operators are so-called because they perform operations on a single operand.

For the purposes of this course, we will only discuss one useful unary operator: ! This operator inverts the value of a Boolean. So, if a Boolean variable has a value of true, using this operator will make the result false.

For example:

boolean myValue = true;
boolean myResult = !myValue;

/*after execution of the line
boolean myResult = !myValue
the variable myResult will have a value of false*/