Learn

You may have noticed that the relational operators did not include an operator for testing “equals to”. In Java, equality operators are used to test equality.

The equality operators are:

  1. ==: equal to.
  2. !=: not equal to.

Equality operators do not require that operands share the same ordering. For example, you can test equality across boolean, char, or int data types. The example below combines assigning variables and using an equality operator:

char myChar = 'A'; int myInt = -2; System.out.println(myChar == myInt);

The example above will print out false because the value of myChar ('A') is not the same value as myInt ('-2').

Instructions

1.

Use any equality operator to directly compare two Boolean values. Do not declare any variables.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?