Comparison Operators


Java comparison operator compares the two operands and return Boolean value true or false.

1. == (is equals to)

System.out.print(10 == 4);
// prints false

System.out.print(10 == 10);
// prints true

2. === (Identical (equals and of same type))

System.out.print(10 === "10");
// prints false

System.out.print(10 === 10);
// prints true

3. != (not equals to)

System.out.print(10 != 4);
// prints true

System.out.print(10 != 10);
// prints false

4. !== (Not Identical)

System.out.print(10 !== "10");
// prints true

System.out.print(10 !== 10);
// prints false

5. > (Greater than)

System.out.print(10 > 20);
// prints true

System.out.print(10 > 10);
// prints false

6. >= (Greater than or equals to)

System.out.print(10 >= 10);
// prints true

System.out.print(10 >= 5);
// prints false

7. < (Less than)

System.out.print(10 < 20);
// prints true

System.out.print(10 < 5);
// prints false

8. <= (Less than or equals to)

System.out.print(10 <= 10);
// prints true

System.out.print(10 <= 5);
// prints false