Equality And Relational Operators in Java

The equality and relational operators in Java are used to determine if value of one operand is greater than, less than, equal to, or not equal to the value of another operand.

These operators return a boolean value determining whether a comparison is true or false. For example if(5 > 7) returns false where as if(5 < 7) returns true. Equality and relational operators are mostly used in conditional statements like if-else or loops like for-loop to determine when to execute the logic with in the conditional statement and for how many times.

Equality and Relational Operators in Java

Operator Description
== equal to
!= not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to

Java Example for equality and relational operators

Output

Note that you must use “==“, not “=” (as “=” is assignment operator), when testing if two primitive values are equal.

That’s all for the topic Equality And Relational Operators in Java. If something is missing or you have something to share about the topic please write a comment.


You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.