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*/