Code Editor

Fantastic! The final Boolean operator we will explore is called not.

  1. The not operator is represented in Java by !.
  2. It will return the opposite of the expression immediately after it. It will return false if the expression is true, and true if the expression is false.

The code below shows all the outcomes of the Boolean operator !:

//The "not" Boolean operator: System.out.println(!false); // prints true System.out.println(!true); // prints false

We can also use the Boolean operator ! with Boolean expressions such as the following:

System.out.println( !(4 <= 10) );

The example above will print out false because the statement "4 is less than or equal to 10" is true, but the ! operator will return the opposite value, which is false.

Report a Bug
If you see a bug or any other issue with this page, please report it here.